-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-49017][SQL] Insert statement fails when multiple parameters are being used #47501
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
Conversation
This reverts commit d54453e.
@cloud-fan could you take a look at this PR? |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/parameters.scala
Outdated
Show resolved
Hide resolved
_.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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala
Outdated
Show resolved
Hide resolved
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
Show resolved
Hide resolved
// It's a function call | ||
val funcCtx = ctx.functionName | ||
val func = withFuncIdentClause( | ||
val func: Expression = withFuncIdentClause( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change?
There was a problem hiding this comment.
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.
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CTESubstitution.scala
Outdated
Show resolved
Hide resolved
@mihailom-db can you fix the merge conflicts? |
# Conflicts: # sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@cloud-fan resolved conflicts, ready for merge |
@MaxGekk could you take a look? |
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala
Outdated
Show resolved
Hide resolved
partition, | ||
cols, | ||
query, | ||
otherPlans.head, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
+1, LGTM. Merging to master. |
@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. |
@MaxGekk checked 3.4 does not have option of parameter markers in |
Please, open a PR with the backport to |
@MaxGekk I have checked now, and there are multiple fixes that were not backported to |
@mihailom-db Please, open separate PRs for the |
…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>
…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>
…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>
…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>
…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>
…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>
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.