【发布时间】:2016-07-14 16:28:40
【问题描述】:
这个问题解释了 Spark 的随机拆分是如何工作的,How does Sparks RDD.randomSplit actually split the RDD,但我不明白 spark 如何跟踪哪些值进入了一个拆分,以便这些相同的值不会进入第二个拆分。
如果我们看一下randomSplit的实现:
def randomSplit(weights: Array[Double], seed: Long): Array[DataFrame] = {
// It is possible that the underlying dataframe doesn't guarantee the ordering of rows in its
// constituent partitions each time a split is materialized which could result in
// overlapping splits. To prevent this, we explicitly sort each input partition to make the
// ordering deterministic.
val sorted = Sort(logicalPlan.output.map(SortOrder(_, Ascending)), global = false, logicalPlan)
val sum = weights.sum
val normalizedCumWeights = weights.map(_ / sum).scanLeft(0.0d)(_ + _)
normalizedCumWeights.sliding(2).map { x =>
new DataFrame(sqlContext, Sample(x(0), x(1), withReplacement = false, seed, sorted))
}.toArray
}
我们可以看到它创建了两个共享相同 sqlContext 和两个不同 Sample(rs) 的 DataFrame。
这两个 DataFrame(s) 如何相互通信,以使第一个中的值不包含在第二个中?
数据是否被提取了两次? (假设 sqlContext 是从数据库中选择的,选择是否被执行了两次?)。
【问题讨论】:
标签: apache-spark apache-spark-sql spark-dataframe apache-spark-mllib