-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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-47939][SQL] Implement a new Analyzer rule to move ParameterizedQuery inside ExplainCommand and DescribeQueryCommand #46209
Closed
vladimirg-db
wants to merge
4
commits into
apache:master
from
vladimirg-db:vladimirg-db/make-explain-and-describe-work-with-parameters
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ced5ad6
to
74dd15c
Compare
vladimirg-db
commented
Apr 25, 2024
/** | ||
* Transform its supervised plan using `transformer` and returns a copy of `SupervisingCommand` | ||
*/ | ||
def withTransformedSupervisedPlan(transformer: (LogicalPlan) => LogicalPlan): LogicalPlan |
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.
This can be rewritten as two methods:
def supervisedPlan: LogicalPlan
def withNewSupervisedPlan(newPlan: LogicalPlan): LogicalPlan
But IMO the current impl is more concise
@milastdbx @stefankandic @cloud-fan hi! This PR is ready for review |
cloud-fan
reviewed
Apr 26, 2024
Mark DescribeQueryCommand and ExplainCommand as SupervisingCommand (they don't expose their wrapped nodes, but supervise them internally). Move ParameterizedQuery into SupervisingCommand for parameters to be resolved correctly.
6115b5f
to
ba9f7cb
Compare
cloud-fan
approved these changes
Apr 29, 2024
thanks, merging to master! |
JacobZheng0927
pushed a commit
to JacobZheng0927/spark
that referenced
this pull request
May 11, 2024
…dQuery inside ExplainCommand and DescribeQueryCommand ### What changes were proposed in this pull request? Mark `DescribeQueryCommand` and `ExplainCommand` as `SupervisingCommand` (they don't expose their wrapped nodes, but supervise them internally). Introduce a new Analyzer rule `MoveParameterizedQueriesDown`, which moves `ParameterizedQuery` inside `SupervisingCommand` for parameters to be resolved correctly. ### Why are the changes needed? Parameterized `EXPLAIN` and `DESCRIBE` queries: - `spark.sql("describe select ?", Array(1)).show();` - `spark.sql("explain select ?", Array(1)).show();` fail with `org.apache.spark.sql.catalyst.ExtendedAnalysisException: [UNBOUND_SQL_PARAMETER] Found the unbound parameter: _16. 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; line 1 pos 16; 'Project [unresolvedalias(posparameter(16))] +- OneRowRelation` ### Does this PR introduce _any_ user-facing change? Yes, parameterized `EXPLAIN` and `DESCRIBE` should start working for users ### How was this patch tested? - Run `sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala` - Run `sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala` - New tests for `SQLQuerySuite` ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#46209 from vladimirg-db/vladimirg-db/make-explain-and-describe-work-with-parameters. Authored-by: Vladimir Golubev <vladimir.golubev@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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Mark
DescribeQueryCommand
andExplainCommand
asSupervisingCommand
(they don't expose their wrapped nodes, but supervise them internally). Introduce a new Analyzer ruleMoveParameterizedQueriesDown
, which movesParameterizedQuery
insideSupervisingCommand
for parameters to be resolved correctly.Why are the changes needed?
Parameterized
EXPLAIN
andDESCRIBE
queries:spark.sql("describe select ?", Array(1)).show();
spark.sql("explain select ?", Array(1)).show();
fail with
org.apache.spark.sql.catalyst.ExtendedAnalysisException: [UNBOUND_SQL_PARAMETER] Found the unbound parameter: _16. Please, fix
argsand provide a mapping of the parameter to either a SQL literal or collection constructor functions such as
map(),
array(),
struct(). SQLSTATE: 42P02; line 1 pos 16; 'Project [unresolvedalias(posparameter(16))] +- OneRowRelation
Does this PR introduce any user-facing change?
Yes, parameterized
EXPLAIN
andDESCRIBE
should start working for usersHow was this patch tested?
sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala
SQLQuerySuite
Was this patch authored or co-authored using generative AI tooling?
No