Skip to content

Conversation

mihailotim-db
Copy link
Contributor

@mihailotim-db mihailotim-db commented Sep 1, 2025

What changes were proposed in this pull request?

Replace literal in SortOrder only under Sort operator

Why are the changes needed?

SPARK-51820 introduced a bug where literal under all SortOrder expressions were treated as ordinals, breaking Windows in Spark Connect. This PR fixes that.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added a test case

Was this patch authored or co-authored using generative AI tooling?

No

@mihailotim-db mihailotim-db force-pushed the mihailotim-db/fix_window_ordinal branch from 6ced69c to 7f033b1 Compare September 1, 2025 15:37
@mihailotim-db mihailotim-db force-pushed the mihailotim-db/fix_window_ordinal branch from 7f033b1 to f3530ab Compare September 2, 2025 06:25
@mihailotim-db mihailotim-db changed the title fix [SPARK-51820][FOLLOWUP][CONNECT] Replace literal in SortOrder only under Sort operator Sep 2, 2025
Copy link
Contributor

@mihailoale-db mihailoale-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -1752,7 +1752,8 @@ class SparkConnectPlanner(
transformUnresolvedExtractValue(exp.getUnresolvedExtractValue)
case proto.Expression.ExprTypeCase.UPDATE_FIELDS =>
transformUpdateFields(exp.getUpdateFields)
case proto.Expression.ExprTypeCase.SORT_ORDER => transformSortOrder(exp.getSortOrder)
case proto.Expression.ExprTypeCase.SORT_ORDER =>
transformSortOrder(order = exp.getSortOrder, shouldReplaceOrdinals = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So using ordinals in ORDER BY in window operator is not possible both in DF and in SQL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, ORDER BY 1 in window is just order by literal

@@ -962,6 +962,69 @@ class SparkConnectPlannerSuite extends SparkFunSuite with SparkConnectPlanTest {
!aggregateExpression.containsPattern(TreePattern.UNRESOLVED_ORDINAL)))
}

test("SPARK-51820 Literals in SortOrder should only be replaced under Sort node") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why add a low-level proto test and not a high-level DF test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To force Spark Connect, otherwise it goes through Dataset.scala API

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 9ada1e7 Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants