Created
April 7, 2013 07:33
-
-
Save muxueqz/5329446 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
#!/usr/bin/env python2 | |
#-*- coding: utf-8 -*- | |
"使用mesos多机的话,在reduceByKey时None的key没有合并,单机无此问题" | |
import dpark | |
def xmap_none(line): | |
for i in range(1, 3): | |
key = (str(i), None) | |
yield (key, ({line}, 1)) | |
def xmap_false(line): | |
for i in range(1, 3): | |
key = (str(i), False) | |
yield (key, ({line}, 1)) | |
def xreduce(line, value): | |
value += line | |
return value | |
user_words = dpark.parallelize(range(1, 3), 3).flatMap( | |
xmap_none ).reduceByKey( xreduce) | |
print 'None:', user_words.collect() | |
user_words = dpark.parallelize(range(1, 3), 3).flatMap( | |
xmap_false ).reduceByKey( xreduce) | |
print '非None', user_words.collect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment