Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Created April 7, 2013 07:33
Show Gist options
  • Save muxueqz/5329446 to your computer and use it in GitHub Desktop.
Save muxueqz/5329446 to your computer and use it in GitHub Desktop.
#!/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