Skip to content

[SPARK-50441][SQL] Fix parametrized identifiers not working when referencing CTEs#48994

Closed
mihailotim-db wants to merge 1 commit intoapache:masterfrom
mihailotim-db:mihailotim-db/cte_identifer
Closed

[SPARK-50441][SQL] Fix parametrized identifiers not working when referencing CTEs#48994
mihailotim-db wants to merge 1 commit intoapache:masterfrom
mihailotim-db:mihailotim-db/cte_identifer

Conversation

@mihailotim-db
Copy link
Copy Markdown
Contributor

@mihailotim-db mihailotim-db commented Nov 27, 2024

What changes were proposed in this pull request?

Fix parametrized identifiers not working when referencing CTEs

Why are the changes needed?

For a query:

with t1 as (select 1) select * from identifier(:cte) using cte as "t1"

the resolution fails because BindParameters can't resolve parameters because it waits for ResolveIdentifierClause to resolve UnresolvedWithCTERelation, but ResolveIdentifierClause can't resolve UnresolvedWithCTERelation until all NamedParameters in the plan are resolved.

Instead of delaying CTE resolution with UnresolvedWithCTERelation, we can remove node entirely and delay the resolution by keeping the original PlanWithUnresolvedIdentifier and moving the CTE resolution to its planBuilder.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added a new test to ParametersSuite

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

No

@github-actions github-actions bot added the SQL label Nov 27, 2024
@mihailotim-db mihailotim-db changed the title fix [SPARK-50441] Fix parametrized identifiers not working when referencing CTEs Nov 27, 2024
@mihailotim-db mihailotim-db force-pushed the mihailotim-db/cte_identifer branch from 13f2813 to 032882d Compare November 27, 2024 19:48
@HyukjinKwon HyukjinKwon changed the title [SPARK-50441] Fix parametrized identifiers not working when referencing CTEs [SPARK-50441][SQL] Fix parametrized identifiers not working when referencing CTEs Nov 28, 2024
@mihailotim-db mihailotim-db force-pushed the mihailotim-db/cte_identifer branch 8 times, most recently from cee2c1e to bdbb221 Compare November 28, 2024 17:06
Copy link
Copy Markdown
Contributor

@cloud-fan cloud-fan Nov 29, 2024

Choose a reason for hiding this comment

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

This part of the comment needs an update, we now use a different planBuilder to delay the CTE lookup.

@mihailotim-db mihailotim-db force-pushed the mihailotim-db/cte_identifer branch from bdbb221 to a40824c Compare November 29, 2024 08:56
@mihailotim-db
Copy link
Copy Markdown
Contributor Author

mihailotim-db commented Nov 29, 2024

@cloud-fan Failures seem unrelated, same test is failing in other PRs as well. Can you check please?

@cloud-fan
Copy link
Copy Markdown
Contributor

The streaming failure is unrelated, I'm merging it to master, thanks!

@cloud-fan cloud-fan closed this in 3fab712 Nov 29, 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.

2 participants