【发布时间】:2020-11-26 06:43:17
【问题描述】:
我有一个非常庞大的数据集,我需要在该数据集上执行连接,以便使用其他列来丰富它。
数据集 A 包含以下结构:-
origin|destination|segment1_origin|segment2_origin|segment3_origin|segment4_origin|segment5_origin|segment6_origin|segment1_destination|segment2_destination|segment3_destination|segment4_destination|segment5_destination|segment6_destination
包含大约 50 亿行
数据集 B 包含以下结构:-
origin|destination|stops|route
数据集 B 实际上保存了数据集 A 中每个片段的信息,几乎是数据集 A 的 6 倍
为了丰富站点和路线的详细信息,我现在正在做的是:-
for (x <- 1 to 6){
DatasetB.withColumnRenamed("stops", s"segment${x}_stops").withColumnRenamed("route", s"segment${x}_route")
DatasetA.join(DatasetB, (col(s"segment${x}departure") === col("origin"))
&& (col(s"segment${x}Arrival") === col("destination")), "left").drop("origin", "destination")
}
而且这个解决方案运行良好。但我担心的是我要加入它 6 次。我只是想知道是否有任何方法可以优化它?这会导致偏斜,并且工作在后期会变慢。
Scala/Spark 数据帧中是否有一种更好的方式来编写它?
【问题讨论】:
标签: scala dataframe apache-spark apache-spark-sql