spark icon indicating copy to clipboard operation
spark copied to clipboard

[SPARK-52388][SQL] Handle named and positional parameters under `PlanWithUnresolvedIdentifier`

Open mihailotim-db opened this issue 6 months ago • 3 comments

What changes were proposed in this pull request?

Handle named and positional parameters when they appear under PlanWithUnresolvedIdentifier.

Why are the changes needed?

For a query like:

INSERT INTO IDENTIFIER(:a)
REPLACE WHERE col1 = :b
SELECT * FROM VALUES(3) as t(col1)

Unresolved plan is going to be:

'NameParameterizedQuery [a, b], [testcat.schema.testtbl, true]
+- 'PlanWithUnresolvedIdentifier namedparameter(a), org.apache.spark.sql.catalyst.parser.AstBuilder$$Lambda$3153/0x000000e801e96788@58c36104
   +- 'Project [*]
      +- SubqueryAlias t
         +- LocalRelation [col1#20]

Because namedParameter(b) is going to be hidden in the planBuilder of PlanWithUnresolvedIdentifier, BindParamters is only going to be able to bind parameter a. However, current implementations is going to completely remove NamedParametrizedQuery node even thought there are still unbound parameters left.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Add a new test to verify that the query pattern is no longer failing.

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

No

mihailotim-db avatar Jun 03 '25 15:06 mihailotim-db

My opinion is that PlanWithUnresolvedIdentifier should hide as few things as possible. We should change PlanWithUnresolvedIdentifier(... => InsertIntoStatement) to InsertIntoStatement(PlanWithUnresolvedIdentifier(... => UnresolvedRelation))

cloud-fan avatar Jun 06 '25 16:06 cloud-fan

My opinion is that PlanWithUnresolvedIdentifier should hide as few things as possible. We should change PlanWithUnresolvedIdentifier(... => InsertIntoStatement) to InsertIntoStatement(PlanWithUnresolvedIdentifier(... => UnresolvedRelation))

I don't like the idea of implementing a fix for a specific operator, mostly because we are bound to find more issues like this. For example, in this case we would fail for any query that has this pattern of a parameter inside PlanWithUnresolvedIdentifier.

mihailotim-db avatar Jun 06 '25 17:06 mihailotim-db

Hiding plans/expressions with a lambda function is evil. We should do the right thing even if it's not easy (need to fix commands one by one).

cloud-fan avatar Jun 06 '25 17:06 cloud-fan

I don't believe this is the right fix. We should fix every place in the parser to not hide plans/expressions within a lambda function.

cloud-fan avatar Aug 06 '25 15:08 cloud-fan

We're closing this PR because it hasn't been updated in a while. This isn't a judgement on the merit of the PR in any way. It's just a way of keeping the PR queue manageable. If you'd like to revive this PR, please reopen it and ask a committer to remove the Stale tag!

github-actions[bot] avatar Nov 15 '25 00:11 github-actions[bot]