forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-48346][SQL] Support for IF ELSE statements in SQL scripts
### What changes were proposed in this pull request? This PR proposes introduction of IF/ELSE statement to SQL scripting language. To evaluate conditions in IF or ELSE IF clauses, introduction of boolean statement evaluator is required as well. Changes summary: - Grammar/parser changes: - `ifElseStatement` grammar rule - `visitIfElseStatement` rule visitor - `IfElseStatement` logical operator - `IfElseStatementExec` execution node: - Internal states - `Condition` and `Body` - Iterator implementation - iterate over conditions until the one that evaluates to `true` is found - Use `StatementBooleanEvaluator` implementation to evaluate conditions - `DataFrameEvaluator`: - Implementation of `StatementBooleanEvaluator` - Evaluates results to `true` if it is single row, single column of boolean type with value `true` - `SqlScriptingInterpreter` - add logic to transform `IfElseStatement` to `IfElseStatementExec` ### Why are the changes needed? We are gradually introducing SQL Scripting to Spark, and IF/ELSE is one of the basic control flow constructs in the SQL language. For more details, check [JIRA item](https://issues.apache.org/jira/browse/SPARK-48346). ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? New tests are introduced to all of the three scripting test suites: `SqlScriptingParserSuite`, `SqlScriptingExecutionNodeSuite` and `SqlScriptingInterpreterSuite`. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#47442 from davidm-db/sql_scripting_if_else. Authored-by: David Milicevic <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
- Loading branch information
Showing
8 changed files
with
663 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.