如何加载一个可以保留bucketing的分块DataFrame?

时间:2017-10-17 21:44:32

标签: apache-spark apache-spark-sql

我已经对数据帧进行了bucketized,即bucketBysaveAsTable

如果我用spark.read.parquet加载它,我就不会从优化中受益(没有改组)。

scala> spark.read.parquet("${spark-warehouse}/tab1").groupBy("a").count.explain(true)
== Physical Plan ==
*HashAggregate(keys=[a#35117], functions=[count(1)], output=[a#35117, count#35126L])
+- Exchange hashpartitioning(a#35117, 200)
   +- *HashAggregate(keys=[a#35117], functions=[partial_count(1)], output=[a#35117, count#35132L])
      +- *FileScan parquet [a#35117] Batched: true, Format: Parquet, Location: InMemoryFileIndex[file:/Users/yann.moisan/projects/teads/data/spark-warehouse/tab1], PartitionFilters: [], PushedFilters: [], ReadSchema: struct<a:int>

我需要使用spark.table加载它以从优化中受益。

scala> spark.table("tab1").groupBy("a").count().explain(true)
== Physical Plan ==
*HashAggregate(keys=[a#149], functions=[count(1)], output=[a#149, count#35140L])
+- *HashAggregate(keys=[a#149], functions=[partial_count(1)], output=[a#149, count#35146L])
   +- *FileScan parquet default.tab1[a#149] Batched: true, Format: Parquet, Location: InMemoryFileIndex[file:/Users/yann.moisan/projects/teads/data/spark-warehouse/tab1], PartitionFilters: [], PushedFilters: [], ReadSchema: struct<a:int>

我不明白为什么Spark在第一种情况下不会自动检测到这种情况,通过使用文件名,例如在这种情况下有点不同part-00007-ca117fc2-2552-4693-b6f7-6b27c7c4bca7_00001.snappy.parquet

1 个答案:

答案 0 :(得分:3)

  

我不明白为什么Spark在第一种情况下不会自动检测到bucketization

简单。不支持使用spark.table未作为分段表加载的分段数据框。