Spark 优化未按预期工作
我正在尝试在 pySpark 中运行一组不同的 SQL 操作。然而,优化并未按预期进行。 理想情况下,spark 在执行实际操作之前优化整个执行计划。
编写的逻辑如下 -
df = spark.read.csv("s3://data/")
df.createOrReplaceTempView("data")
df2=spark.sql("select * from data where p_report_date=20200901")
df2.createOrReplaceTempView("data2")
df3=spark.sql("select * from data2")
df3.write.mode("overwrite").format("parquet").save("s3_path_2")
数据文件存储在分区中 -
s3://data/p_report_date=20200901,
s3://data/p_report_date=20200902
s3://data/p_report_date=20200903
所以基本上动作是在 df3 中调用的,在此之前所有的都只是转换。 我假设 Spark 仅读取 df2(s3://data/p_report_date=20200901) 中的 where 子句中提到的文件夹。但它首先读取 s3://data 中的所有分区 &然后过滤 p_report_date。
我们正在使用 EMR6.5.0 和 EMR6.5.0。 Spark-3.1.2
问题 - 为什么 Spark 不优化查询以仅读取提到的文件夹而不是读取所有内容?
I am trying to run a different set of SQL operations in pySpark. However, the optimization is not happening as expected.
Ideally, spark optimizes the whole execution plan before doing the actual thing.
Logic written is as below -
df = spark.read.csv("s3://data/")
df.createOrReplaceTempView("data")
df2=spark.sql("select * from data where p_report_date=20200901")
df2.createOrReplaceTempView("data2")
df3=spark.sql("select * from data2")
df3.write.mode("overwrite").format("parquet").save("s3_path_2")
Data files are stored with partitions -
s3://data/p_report_date=20200901,
s3://data/p_report_date=20200902
s3://data/p_report_date=20200903
So basically the action is called in df3, before that all is just transformations.
I am assuming spark to read only the folder which is mentioned in the where clause in df2(s3://data/p_report_date=20200901). But it's reading all the partitions in s3://data first & then filtering the p_report_date.
We are using EMR6.5.0 & Spark-3.1.2
Question - Why is spark not optimizing the query to read only the mentioned folder first in place of reading everything??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论