【发布时间】:2018-05-21 14:45:48
【问题描述】:
我使用 Spark 2.1.1。我按小时循环对输入 DS (inputDs) 进行许多连接和选择,如下所示:
val myDs = Iterator.iterate(fromDate)(_.plus(ofHours(1))).takeWhile(_.isBefore(toDate)).map(next => {
getDsForOneHour(inputDs, next.getYear, next.getMonthValue, next.getDayOfMonth, next.getHour)
}).reduce(_.union(_))
def getDsForOneHour(ds: Dataset[I], year:Int, month:Int, day:Int, hour: Int)(implicit sql: SQLImplicits):Dataset[I]= {
ds.where(col("year") === year and col("month") === month and col("day") === day and col("hour") === hour)
}
我使用 spark-testing-base 运行该代码,完成一个月的操作大约需要 3 分钟(约 30*24 个联合和选择)。这些都是懒惰的操作,我想知道为什么 Spark 构建 myDs 需要这么多时间?
【问题讨论】:
-
这就是计算执行计划的成本。 Spark unionAll multiple dataframes 应该可以帮到你。
标签: apache-spark apache-spark-sql