Spark 优化未按预期工作

发布于 2025-01-13 05:06:59 字数 814 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文