Skip to content

Conversation

mihailom-db
Copy link
Contributor

What changes were proposed in this pull request?

Fix for multiple parameters support.

Why are the changes needed?

The use of multiple parameters with identifiers were broken

Does this PR introduce any user-facing change?

Yes, look at tests.

How was this patch tested?

New tests added to ParametersSuite.

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

No.

@github-actions github-actions bot added the SQL label Jul 26, 2024
@HyukjinKwon HyukjinKwon changed the title [SPARK-49017] Insert statement fails when multiple parameters are being used [SPARK-49017][SQL] Insert statement fails when multiple parameters are being used Jul 27, 2024
@mihailom-db
Copy link
Contributor Author

@cloud-fan could you take a look at this PR?

_.containsAnyPattern(UNRESOLVED_IDENTIFIER, UNRESOLVED_IDENTIFIER_WITH_CTE)) {
case p: PlanWithUnresolvedIdentifier if p.identifierExpr.resolved =>
executor.execute(p.planBuilder.apply(evalIdentifierExpr(p.identifierExpr)))
executor.execute(p.planBuilder.apply(evalIdentifierExpr(p.identifierExpr), p.otherPlans))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a problem is when to invoke the plan builder. Shall we wait for all p.otherPlans to be resolved first? Without a clear trigger condition, we may hit rule order issues.

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, that is true. That is why I tried to add a couple of tests with interleaving of identifiers and non-identifiers. I can pass one more time through AstBuilder, as I believe only InsertInto and one more LogicalPlans were changed to have otherPlans as parameters.

// It's a function call
val funcCtx = ctx.functionName
val func = withFuncIdentClause(
val func: Expression = withFuncIdentClause(
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, there are two withFuncIdentClause, one that takes LogicalPlan and other with Expression. Compiler was not smart to pick up which one it was.

@cloud-fan
Copy link
Contributor

@mihailom-db can you fix the merge conflicts?

# Conflicts:
#	sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@mihailom-db
Copy link
Contributor Author

@cloud-fan resolved conflicts, ready for merge

@mihailom-db
Copy link
Contributor Author

@MaxGekk could you take a look?

partition,
cols,
query,
otherPlans.head,
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that everywhere you call .head, it won't fail with NoSuchElementException. Could you clarify your assumption, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For all the places where we call .head we have otherPlans that was defined as Seq(query), so it will have exactly one element. But Seq was used, if in the future the need for multiple plans is needed.

Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

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

The last changes are trivial. Just waiting for a success build.

@MaxGekk
Copy link
Member

MaxGekk commented Aug 19, 2024

+1, LGTM. Merging to master.
Thank you, @mihailom-db and @cloud-fan for review.

@MaxGekk MaxGekk closed this in 11b682c Aug 19, 2024
@MaxGekk
Copy link
Member

MaxGekk commented Aug 19, 2024

@mihailom-db You pointed out only 4.0.0 as the affected version in SPARK-49017. Do the previous versions suffer from the same issue, and shall we backport the changes to other branches. Please, double check and confirm.

@mihailom-db
Copy link
Contributor Author

@MaxGekk checked 3.4 does not have option of parameter markers in IDENTIFIER(...), but 3.5 seems to suffer from the same error, so backport is needed

@MaxGekk
Copy link
Member

MaxGekk commented Aug 19, 2024

but 3.5 seems to suffer from the same error, so backport is needed

Please, open a PR with the backport to branch-3.5.

@mihailom-db
Copy link
Contributor Author

@MaxGekk I have checked now, and there are multiple fixes that were not backported to branch-3.5, so I would say this one does not have to be backported as well. For example a fix for ExpressionWithUnresolvedIdentifier was not backported and this blocks backport of this PR as well.

@MaxGekk
Copy link
Member

MaxGekk commented Aug 20, 2024

I have checked now, and there are multiple fixes that were not backported to branch-3.5

@mihailom-db Please, open separate PRs for the branch-3.5 with bug fixes.

MaxGekk pushed a commit that referenced this pull request Aug 20, 2024
…rs are being used

### What changes were proposed in this pull request?
Fix for multiple parameters support.

This PR is a backport of #47501.

### Why are the changes needed?
The use of multiple parameters with identifiers were broken

### Does this PR introduce _any_ user-facing change?
Yes, look at tests.

### How was this patch tested?
New tests added to ParametersSuite.

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

Closes #47814 from mihailom-db/fixParametersBackport.

Authored-by: Mihailo Milosevic <mihailo.milosevic@databricks.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
IvanK-db pushed a commit to IvanK-db/spark that referenced this pull request Sep 20, 2024
…e being used

### What changes were proposed in this pull request?
Fix for multiple parameters support.

### Why are the changes needed?
The use of multiple parameters with identifiers were broken

### Does this PR introduce _any_ user-facing change?
Yes, look at tests.

### How was this patch tested?
New tests added to ParametersSuite.

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

Closes apache#47501 from mihailom-db/fixParameters.

Authored-by: Mihailo Milosevic <mihailo.milosevic@databricks.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
attilapiros pushed a commit to attilapiros/spark that referenced this pull request Oct 4, 2024
…e being used

### What changes were proposed in this pull request?
Fix for multiple parameters support.

### Why are the changes needed?
The use of multiple parameters with identifiers were broken

### Does this PR introduce _any_ user-facing change?
Yes, look at tests.

### How was this patch tested?
New tests added to ParametersSuite.

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

Closes apache#47501 from mihailom-db/fixParameters.

Authored-by: Mihailo Milosevic <mihailo.milosevic@databricks.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
himadripal pushed a commit to himadripal/spark that referenced this pull request Oct 19, 2024
…e being used

### What changes were proposed in this pull request?
Fix for multiple parameters support.

### Why are the changes needed?
The use of multiple parameters with identifiers were broken

### Does this PR introduce _any_ user-facing change?
Yes, look at tests.

### How was this patch tested?
New tests added to ParametersSuite.

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

Closes apache#47501 from mihailom-db/fixParameters.

Authored-by: Mihailo Milosevic <mihailo.milosevic@databricks.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
cloud-fan added a commit that referenced this pull request Nov 12, 2024
…dentifier

### What changes were proposed in this pull request?

This PR reverts #46580 (the tests are left) because it's no longer needed after #47501 . The `PlanWithUnresolvedIdentifier` becomes more flatten and all its children will be resolved by the early batch already.

### Why are the changes needed?

code cleanup

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

existing tests

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

no

Closes #48786 from cloud-fan/ident.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
a0x8o added a commit to a0x8o/spark that referenced this pull request Nov 12, 2024
…dentifier

### What changes were proposed in this pull request?

This PR reverts apache/spark#46580 (the tests are left) because it's no longer needed after apache/spark#47501 . The `PlanWithUnresolvedIdentifier` becomes more flatten and all its children will be resolved by the early batch already.

### Why are the changes needed?

code cleanup

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

existing tests

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

no

Closes #48786 from cloud-fan/ident.

Authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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