首页 > 解决方案 > Spark 过滤器/谓词下推在 ORC 文件中是否按预期工作?

问题描述

而“spark.sql.orc.filterPushdown”等于 false(默认情况下)。以下语句需要 3 分钟才能执行。

val result = spark.read.schema(schema).orc("s3a://......./*")
result.select("a","b").where(col("a")===1318138224).explain(extended = true)
result.select("a","b").where(col("a")===1318138224).show()

在物理计划上它说; PushedFilters: [IsNotNull(a), EqualTo(a,1318138224)]

因此,即使通过查看“PushedFilters”语句默认禁用“filterPushdown”,我认为 spark 会以某种方式下推过滤器。

但是在将 spark.sql.orc.filterPushdown 设置为“true”后,相同的代码片段大约需要 30 秒。奇怪的是,物理计划是一样的。

所以我查看了 SparkUI 的“阶段”部分,输入大小的数量不同。

spark.conf.set("spark.sql.orc.filterPushdown", false) spark.conf.set(

spark.conf.set("spark.sql.orc.filterPushdown", true) spark.conf.set(

所以我觉得即使PushedFilters在Physical上填充了一些参数(不是空的),我也喜欢阅读orc文件,这并不意味着Spark实际上做了下推谓词/过滤器?

还是有一点我错过了?

标签: scalaapache-sparkapache-spark-sqlorc

解决方案


查询计划不受filterPushdown配置影响(对于 parquet 或 orc)。Spark 总是尝试将过滤器推送到源。配置控制是否允许源应用数据跳过。有时即使配置设置为 true,在某些情况下也可能不会发生数据跳过(由于错误、列统计信息不正确或不支持类型)。

您还可以在 web ui 的 SQL 选项卡中检查“输出行数”。

它是谓词下推和分区修剪后读取的行数。

Scan parquet

number of files read: 1
scan time total (min, med, max )
18.7 s (12 ms, 214 ms, 841 ms )
metadata time: 0 ms
size of files read: 783.9 MiB
number of output rows: 100,000,000

推荐阅读