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-49913][SQL] Add check for unique label names in nested labeled…
… scopes ### What changes were proposed in this pull request? We are introducing checks for unique label names. New rules for label names: - Labels can't have the same name as some of the labels in scope surrounding them - Labels can have the same name as other labels in the same scope **Valid** code: ``` BEGIN lbl: BEGIN SELECT 1; END; lbl: BEGIN SELECT 2; END; BEGIN lbl: WHILE 1=1 DO LEAVE lbl; END WHILE; END; END ``` **Invalid** code: ``` BEGIN lbl: BEGIN lbl: BEGIN SELECT 1; END; END; END ``` #### Design explanation: Even though there are _Listeners_ with `enterRule` and `exitRule` methods to check labels before and remove them from `seenLabels` after visiting node, we favor this approach because minimal changes were needed and code is more compact to avoid dependency issues. Additionally, generating label text would need to be done in 2 places and we wanted to avoid duplicated logic: - `enterRule` - `visitRule` ### Why are the changes needed? It will be needed in future when we release Local Scoped Variables for SQL Scripting so users can target variables from outer scopes if they are shadowed. ### How was this patch tested? New unit tests in 'SqlScriptingParserSuite.scala'. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48795 from miland-db/milan-dankovic_data/unique_labels_scripting. Authored-by: Milan Dankovic <milan.dankovic@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
- Loading branch information
Showing
5 changed files
with
430 additions
and
61 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
Oops, something went wrong.