-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-24556][SQL] Always rewrite output partitioning in ReusedExchangeExec and InMemoryTableScanExec #21564
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
f37139b
0ef99cc
405ba94
9da85e0
85dc1bc
7d1c2f2
6744a9e
dcd0ce9
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 |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import org.apache.spark.sql.catalyst.InternalRow | |
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.plans.QueryPlan | ||
| import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning} | ||
| import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning, RangePartitioning} | ||
| import org.apache.spark.sql.execution.{ColumnarBatchScan, LeafExecNode, SparkPlan, WholeStageCodegenExec} | ||
| import org.apache.spark.sql.execution.vectorized._ | ||
| import org.apache.spark.sql.types._ | ||
|
|
@@ -170,6 +170,8 @@ case class InMemoryTableScanExec( | |
| override def outputPartitioning: Partitioning = { | ||
| relation.cachedPlan.outputPartitioning match { | ||
| case h: HashPartitioning => updateAttribute(h).asInstanceOf[HashPartitioning] | ||
| case r: RangePartitioning => | ||
| r.copy(ordering = r.ordering.map(updateAttribute(_).asInstanceOf[SortOrder])) | ||
|
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. why not just Moreover, in order to avoid the same issue in the future with other cases, have you considered doing something like: ?
Member
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. Not all
Author
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.
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. yes, you're right @viirya , thanks. Then, I'd propose something like: what do you think?
Member
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. I think
Member
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. Hmm,
Author
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.
How do you think?
Member
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. For In above example,
Author
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. @viirya From It means "[i#54, j#55, m#58, n#59]" corresponds to "[i#5, j#6, m#15, n#16]", so we can always replace
Member
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. Looks correct. |
||
| case _ => relation.cachedPlan.outputPartitioning | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import org.apache.spark.broadcast | |
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeMap, Expression, SortOrder} | ||
| import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning} | ||
| import org.apache.spark.sql.catalyst.plans.physical.{HashPartitioning, Partitioning, RangePartitioning} | ||
| import org.apache.spark.sql.catalyst.rules.Rule | ||
| import org.apache.spark.sql.execution.{LeafExecNode, SparkPlan, UnaryExecNode} | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
@@ -71,6 +71,8 @@ case class ReusedExchangeExec(override val output: Seq[Attribute], child: Exchan | |
|
|
||
| override def outputPartitioning: Partitioning = child.outputPartitioning match { | ||
| case h: HashPartitioning => h.copy(expressions = h.expressions.map(updateAttr)) | ||
| case r: RangePartitioning => | ||
| r.copy(ordering = r.ordering.map(updateAttr(_).asInstanceOf[SortOrder])) | ||
| case other => other | ||
|
Member
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. LGTM |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2270,4 +2270,15 @@ class DataFrameSuite extends QueryTest with SharedSQLContext { | |
| val mapWithBinaryKey = map(lit(Array[Byte](1.toByte)), lit(1)) | ||
| checkAnswer(spark.range(1).select(mapWithBinaryKey.getItem(Array[Byte](1.toByte))), Row(1)) | ||
| } | ||
|
|
||
| test("SPARK-24556: ReusedExchange should rewrite output partitioning for RangePartitioning") { | ||
|
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 is not an end-to-end test, let's put it in
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. please also mention cached table in PR title |
||
| val df = Seq(1 -> "a").toDF("i", "j") | ||
| val df1 = df.as("t1") | ||
| val df2 = df.as("t2") | ||
| val shuffles = df1.orderBy("j").join(df2.orderBy("j"), $"t1.i" === $"t2.i", "right") | ||
| .cache().orderBy($"t2.j").queryExecution.executedPlan.collect { | ||
| case e: ShuffleExchangeExec => e | ||
| } | ||
| assert(shuffles.isEmpty) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why
RangePartitioningisn't included at first.