[SPARK-56147][SQL] spark-sql cli correctly handles SQL Scripting compound blocks#54946
Open
pan3793 wants to merge 3 commits intoapache:masterfrom
Open
[SPARK-56147][SQL] spark-sql cli correctly handles SQL Scripting compound blocks#54946pan3793 wants to merge 3 commits intoapache:masterfrom
spark-sql cli correctly handles SQL Scripting compound blocks#54946pan3793 wants to merge 3 commits intoapache:masterfrom
Conversation
Member
Author
|
cc @srielau @cloud-fan, could you please take a look? |
spark-sql cli correctly handles SQL Scripting compound blocksspark-sql cli correctly handles SQL Scripting compound blocks
This file contains hidden or 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
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?
The
spark-sqlcli now correctly handles SQL Scripting compound blocks (e.g.,BEGIN...END,IF...END IF,WHILE...DO...END WHILE,CASE...END CASE) by tracking block nesting depth during input processing.Changes:
SqlScriptBlockTrackerclass in the companion object that tracks SQL Scripting block depth by scanning keyword tokens (BEGIN,END,CASE,IF,DO,LOOP,REPEAT) while correctly handling decorative suffixes afterEND(e.g.,END IF,END CASE).splitSemiColonto useSqlScriptBlockTrackerso semicolons inside compound blocks are not treated as statement boundaries.sqlScriptingBlockDepthand continue accumulating input when the user is still inside an open scripting block.Why are the changes needed?
The
spark-sqlCLI uses semicolons to determine statement boundaries, both for splitting multi-statement input (splitSemiColon) and for deciding when to execute in interactive mode (line ends with;). SQL Scripting compound blocks use semicolons as internal statement terminators (e.g.,BEGIN SELECT 1; SELECT 2; END;), so the CLI incorrectly splits or prematurely executes incomplete blocks.For example, in interactive mode:
After this change, the CLI waits until the block is fully closed (
END;) before executing.Does this PR introduce any user-facing change?
Yes. The
spark-sqlCLI now correctly accepts multi-line SQL Scripting blocks in both interactive mode and file/-emode without prematurely splitting or executing them.How was this patch tested?
New UTs are added in
CliSuite.scalaWith additional playing with
spark-sql:Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Sonnet 4.6), OpenCode (MiMo V2 Pro)