Skip to content
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

[SPARK-50322][SQL] Fix parameterized identifier in a sub-query #48847

Closed
wants to merge 3 commits into from

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Nov 14, 2024

What changes were proposed in this pull request?

In the PR, I propose to postpone parameters resolution till UnresolvedWithCTERelations is resolved.

Why are the changes needed?

To fix the query failure:

execute immediate 'with v1 as (select * from tt1 where 1 = (Select * from identifier(:tab))) select * from v1' using 'tt1' as tab;
[UNBOUND_SQL_PARAMETER] Found the unbound parameter: tab. Please, fix `args` and provide a mapping of the parameter to either a SQL literal or collection constructor functions such as `map()`, `array()`, `struct()`. SQLSTATE: 42P02

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running new test:

$ build/sbt "sql/test:testOnly org.apache.spark.sql.ParametersSuite

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

No.

@github-actions github-actions bot added the SQL label Nov 14, 2024
@MaxGekk MaxGekk changed the title [WIP] Fix parameterized identifier in a sub-query [SPARK-50322][SQL] Fix parameterized identifier in a sub-query Nov 14, 2024
@MaxGekk MaxGekk marked this pull request as ready for review November 14, 2024 19:34
@@ -189,7 +189,8 @@ object BindParameters extends ParameterizedQueryProcessor with QueryErrorsBase {
// We should wait for `CTESubstitution` to resolve CTE before binding parameters, as CTE
// relations are not children of `UnresolvedWith`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking of a different approach: shall we explicitly match UnresolvedWith here and bind parameters in the CTE relations? Then we no longer need this hack to delay parameter binding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we do that in 2 steps: 1. fix the issue, 2. do the proposed refactoring? It seems less risky, so, the first patch could be backported more safely.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@MaxGekk
Copy link
Member Author

MaxGekk commented Nov 15, 2024

Merging to master. Thank you, @srielau and @cloud-fan for review.

@MaxGekk MaxGekk closed this in d317002 Nov 15, 2024
@MaxGekk
Copy link
Member Author

MaxGekk commented Nov 15, 2024

We don't need to backport this fix to branch-3.5 because it doesn't have the changes #47180.

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