Skip to content

Conversation

@mihailomilosevic2001
Copy link
Contributor

@mihailomilosevic2001 mihailomilosevic2001 commented Aug 2, 2024

What changes were proposed in this pull request?

Fix for between with ScalarSubqueries.

Why are the changes needed?

There is a regression introduced from a previous PR #44299. This needs to be addressed as between operator was completely broken with resolved ScalarSubqueries.

Does this PR introduce any user-facing change?

No, the bug is not release yet.

How was this patch tested?

Tests added to golden file.

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

No.

@github-actions github-actions bot added the SQL label Aug 2, 2024
@mihailomilosevic2001 mihailomilosevic2001 changed the title [SPARK-49063][SQL]Fix Between with ScalarSubqueries [SPARK-49063][SQL] Fix Between with ScalarSubqueries Aug 2, 2024
.createWithDefault(true)

val OPTIMIZE_BETWEEN =
buildConf("spark.sql.optimizeBetween")
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not only an optimization, but also a correctness fix if the BETWEEN input is nondeterministic. I think a legacy config is better here. How about spark.sql.legacy.duplicateBetweenInput? By default it's false, and people can set it to true to restore to the legacy behavior.

@HyukjinKwon
Copy link
Member

Fix for between with ScalarSubqueries.

What does this PR fix?

@mihailomilosevic2001
Copy link
Contributor Author

@HyukjinKwon This ticket's PR https://issues.apache.org/jira/browse/SPARK-46366 introduced an optimization for Between expression. Unfortunately it lead to ScalarSubqueries being firstly resolved before duplicated. This lead to failure in RewriteCorrelatedScalarSubqueries as resolved Subqueries will not need another alias resolution, so we would end up left joining the same query twice. Left join is unresolved if both sides have the same alias.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 6bf6088 Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants