Created
January 10, 2018 16:12
-
-
Save bkj/035ec84f108df38a6edba350d02c62a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pyspark -- partition by key | |
def partition_by_key(x): | |
key_lookup = x.keys().distinct().collect() | |
key_lookup = dict(zip(key_lookup), range(len(key_lookup))) | |
return x.partitionBy(len(key_lookup), partitionFunc=lambda k: key_lookup[k]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment