[ 
https://issues.apache.org/jira/browse/SPARK-62263?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

XiDuo You reassigned SPARK-62263:
---------------------------------

    Assignee: XiDuo You

> Keep the constant spelling of a foldable alias in projected partitioning and 
> ordering
> -------------------------------------------------------------------------------------
>
>                 Key: SPARK-62263
>                 URL: https://issues.apache.org/jira/browse/SPARK-62263
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 5.0.0
>            Reporter: XiDuo You
>            Assignee: XiDuo You
>            Priority: Major
>              Labels: pull-request-available
>
> {{AliasAwareOutputExpression.aliasMap}} treats every {{Alias(child, _)}} as a 
> column identity, including a foldable child such as {{1 AS one}}. 
> {{projectExpression}} then replaces the literal inside the child's inherited 
> partitioning/ordering expressions with the alias attribute and drops the 
> original expression ({{a + 1}} becomes {{a + one}}), so the projection no 
> longer satisfies a requirement on {{a + 1}} and the planner inserts a 
> redundant exchange (or sort). The symmetric case is an alias-spelled 
> requirement ({{a + one}}), which loses its match where 
> {{FoldablePropagation}} cannot rewrite it to the constant.
> Repro (Int key, AQE and broadcast disabled):
> {code:java}
> val base = spark.range(10).selectExpr("cast(id as int) as a")
> val left = base.repartition($"a" + 1).selectExpr("a", "1 as one")
> val right = base.selectExpr("a as k")
> left.join(right, left("a") + 1 === right("k"))
> {code}
> The left side is shuffled twice with {{hashpartitioning(a + 1)}} (3 
> shuffles). After the fix it reuses the user's repartition (2 shuffles).
> Fix: project the inherited partitioning/ordering twice. The first pass keeps 
> the alias-projected spellings; the second pass keeps the matched foldable 
> leaves, so the projection advertises both {{a + one}} and {{a + 1}}. Both 
> spellings are required because {{FoldablePropagation}} rewrites an 
> alias-spelled requirement to the constant only through some operators (not 
> across {{CollectMetrics}}, a cached or checkpointed relation, a union, or a 
> stream-stream join), and nothing rewrites the constant back.
> Affects 3.5.0 and later (the alias map was introduced by SPARK-42049).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to