我需要为我的每个元组生成唯一的 id [相当于 ETL 维度处理中的代理键生成]
def attachLongSurrogateKeys[T: ClassTag](dim: RDD[T], nextSurrogateKey: Long): (RDD[(T, Long)], Long) = {
val dimensionWithSK = dim.zipWithUniqueId.map { case (x, y) => (x, y + nextSurrogateKey) }
val newSurrogateKey = dimensionWithSK.map { case (row, sk) => sk }.max
(dimensionWithSK, newSurrogateKey)
}
我将处理 40 亿行。我有点担心第 3 行的性能,其中获取生成的代理键的最大值..
有没有更好的清洁方法来达到同样的效果?