Browse Source

[frontend] Advance the 'AND' rule in the definition of 'between' syntax for Hive and Presto (#3561)

* fix: SQL parser: Move the '<between> AND' rule in the lexical definitions of Hive and Presto ahead of the 'AND' rule to avoid auto-completion errors in cases like "where x between 'a' and 'b' a". The keyword 'AND' with state 'between' is treated as a normal 'AND'. Other SQL syntax such as Flink, SQL, etc. are correct.

* [frontend] Supplementing test cases for keyword completion of the SQL 'between and' statement.

---------

Co-authored-by: fangguiliang <fangguiliang@bigo.sg>
laochake 1 year ago
parent
commit
a46b3b64b4

File diff suppressed because it is too large
+ 292 - 292
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


File diff suppressed because it is too large
+ 292 - 292
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


+ 2 - 2
desktop/core/src/desktop/js/parse/sql/hive/jison/sql.jisonlex

@@ -26,6 +26,8 @@
 '\u2020'                             { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
 '\u2021'                             { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
 
+<between>'AND'                       { this.popState(); return 'BETWEEN_AND'; }
+
 // Reserved Keywords
 'ALL'                                { return 'ALL'; }
 'ALTER'                              { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
@@ -322,8 +324,6 @@ STORED\s+AS\s+DIRECTORIES            { return 'STORED_AS_DIRECTORIES'; }
 '['                                  { return '['; }
 ']'                                  { return ']'; }
 
-<between>'AND'                       { this.popState(); return 'BETWEEN_AND'; }
-
 // --- UDFs ---
 AVG\s*\(                             { yy.lexer.unput('('); yytext = 'avg'; parser.addFunctionLocation(yylloc, yytext); return 'AVG'; }
 CAST\s*\(                            { yy.lexer.unput('('); yytext = 'cast'; parser.addFunctionLocation(yylloc, yytext); return 'CAST'; }

+ 8 - 0
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Select.test.js

@@ -1593,6 +1593,14 @@ describe('hiveAutocompleteParser.js SELECT statements', () => {
       });
     });
 
+    it('should suggest keywords for "SELECT day, count(cnt) from foo.bar WHERE cnt BETWEEN 1 AND 2 group by day |"', () => {
+      assertAutoComplete({
+        beforeCursor: 'SELECT day, count(cnt) from foo.bar WHERE cnt BETWEEN 1 AND 2 group by day ',
+        afterCursor: '',
+        containsKeywords: ['HAVING', 'ORDER BY', 'LIMIT']
+      });
+    });
+
     it('should suggest keywords for "SELECT row_number() OVER (PARTITION BY a ORDER BY b |"', () => {
       assertAutoComplete({
         beforeCursor: 'SELECT row_number() OVER (PARTITION BY a ORDER BY b ',

+ 2 - 1
desktop/core/src/desktop/js/parse/sql/presto/jison/sql.jisonlex

@@ -26,6 +26,8 @@
 '\u2020'                             { parser.yy.partialCursor = false; parser.yy.cursorFound = yylloc; return 'CURSOR'; }
 '\u2021'                             { parser.yy.partialCursor = true; parser.yy.cursorFound = yylloc; return 'PARTIAL_CURSOR'; }
 
+<between>'AND'                       { this.popState(); return 'BETWEEN_AND'; }
+
 // Reserved Keywords
 'ALL'                                { return 'ALL'; }
 'ALTER'                              { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
@@ -291,7 +293,6 @@ STORED\s+AS\s+DIRECTORIES            { return 'STORED_AS_DIRECTORIES'; }
 '['                                  { return '['; }
 ']'                                  { return ']'; }
 
-<between>'AND'                       { this.popState(); return 'BETWEEN_AND'; }
 
 // --- UDFs ---
 AVG\s*\(                             { yy.lexer.unput('('); yytext = 'avg'; parser.addFunctionLocation(yylloc, yytext); return 'AVG'; }

File diff suppressed because it is too large
+ 261 - 261
desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js


File diff suppressed because it is too large
+ 261 - 261
desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js


Some files were not shown because too many files changed in this diff