我很难在Spark文档操作中找到导致shuffle和操作的操作.在这个列表中,哪些确实会导致混乱而哪些不会导致混乱?
地图和过滤器没有.但是,我不确定其他人.
map(func)
filter(func)
flatMap(func)
mapPartitions(func)
mapPartitionsWithIndex(func)
sample(withReplacement, fraction, seed)
union(otherDataset)
intersection(otherDataset)
distinct([numTasks]))
groupByKey([numTasks])
reduceByKey(func, [numTasks])
aggregateByKey(zeroValue)(seqOp, combOp, [numTasks])
sortByKey([ascending], [numTasks])
join(otherDataset, [numTasks])
cogroup(otherDataset, [numTasks])
cartesian(otherDataset)
pipe(command, [envVars])
coalesce(numPartitions)
Run Code Online (Sandbox Code Playgroud) 我是Apache Spark的新手,正在学习基本的功能.有一个小小的疑问.假设我有一个元组的RDD(键,值),并希望从中获得一些独特的元素.我使用distinct()函数.我想知道函数在什么基础上认为元组是完全不同的?它是基于键,值,还是两者兼而有之?
Apache Spark pyspark.RDDAPI文档提到groupByKey()效率低下.相反,它是推荐使用reduceByKey(),aggregateByKey(),combineByKey(),或foldByKey()代替.这将导致在shuffle之前在worker中进行一些聚合,从而减少跨工作人员的数据混乱.
给定以下数据集和groupByKey()表达式,什么是等效且有效的实现(减少的跨工作者数据混洗),它不使用groupByKey(),但提供相同的结果?
dataset = [("a", 7), ("b", 3), ("a", 8)]
rdd = (sc.parallelize(dataset)
.groupByKey())
print sorted(rdd.mapValues(list).collect())
Run Code Online (Sandbox Code Playgroud)
输出:
[('a', [7, 8]), ('b', [3])]
Run Code Online (Sandbox Code Playgroud)