-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33482][SQL] Fix FileScan canonicalization #31820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
99c1482
c0fb9b2
20624d1
52cc2ca
483686d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,13 @@ case class BatchScanExec( | |
| } | ||
|
|
||
| override def doCanonicalize(): BatchScanExec = { | ||
| this.copy(output = output.map(QueryPlan.normalizeExpressions(_, output))) | ||
| val canonicalizedScan = scan match { | ||
| case s: FileScan => | ||
| s.withFilters(QueryPlan.normalizePredicates(s.partitionFilters, output), | ||
| QueryPlan.normalizePredicates(s.dataFilters, output)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but is a bit hacky as it doesn't apply to all the I think we should add doc in the |
||
| case _ => scan | ||
| } | ||
| this.copy(output = output.map(QueryPlan.normalizeExpressions(_, output)), | ||
| scan = canonicalizedScan) | ||
peter-toth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,7 +86,7 @@ trait FileScan extends Scan | |
|
|
||
| override def equals(obj: Any): Boolean = obj match { | ||
| case f: FileScan => | ||
| fileIndex == f.fileIndex && readSchema == f.readSchema | ||
| fileIndex == f.fileIndex && readSchema == f.readSchema && | ||
|
||
| ExpressionSet(partitionFilters) == ExpressionSet(f.partitionFilters) && | ||
| ExpressionSet(dataFilters) == ExpressionSet(f.dataFilters) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ import org.apache.spark.sql.execution.datasources.{LogicalRelation, SchemaColumn | |
| import org.apache.spark.sql.execution.datasources.v2.BatchScanExec | ||
| import org.apache.spark.sql.execution.datasources.v2.orc.OrcScan | ||
| import org.apache.spark.sql.execution.datasources.v2.parquet.ParquetScan | ||
| import org.apache.spark.sql.execution.exchange.ReusedExchangeExec | ||
| import org.apache.spark.sql.execution.joins.{BroadcastHashJoinExec, CartesianProductExec, SortMergeJoinExec} | ||
| import org.apache.spark.sql.functions._ | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
@@ -4065,6 +4066,33 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark | |
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-33482: Fix FileScan canonicalization") { | ||
| Seq(true, false).foreach { aqe => | ||
| withSQLConf(SQLConf.USE_V1_SOURCE_LIST.key -> "", | ||
| SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> aqe.toString) { | ||
|
||
| withTempPath { path => | ||
| spark.range(5).toDF().write.mode("overwrite").parquet(path.toString) | ||
| withTempView("t") { | ||
| spark.read.parquet(path.toString).createOrReplaceTempView("t") | ||
| val df = sql( | ||
| """ | ||
| |SELECT * | ||
| |FROM t AS t1 | ||
| |JOIN t AS t2 ON t2.id = t1.id | ||
| |JOIN t AS t3 ON t3.id = t2.id | ||
| |""".stripMargin) | ||
| df.collect() | ||
| df.explain() | ||
|
||
| val reusedExchanges = collect(df.queryExecution.executedPlan) { | ||
| case r: ReusedExchangeExec => r | ||
| } | ||
| assert(reusedExchanges.size == 1) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| case class Foo(bar: Option[String]) | ||
Uh oh!
There was an error while loading. Please reload this page.