Преглед изворни кода

HUE-6835 [autocomplete] Improve Impala UPDATE autocomplete for Kudu

Johan Ahlen пре 8 година
родитељ
комит
d967eff

+ 36 - 7
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_update.jison

@@ -23,16 +23,31 @@ DataManipulation_EDIT
  ;
 
 UpdateStatement
- : 'UPDATE' TargetTable 'SET' SetClauseList OptionalWhereClause
+ : 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
  ;
 
 UpdateStatement_EDIT
- : 'UPDATE' TargetTable_EDIT 'SET' SetClauseList OptionalWhereClause
- | 'UPDATE' TargetTable 'SET' SetClauseList_EDIT OptionalWhereClause
- | 'UPDATE' TargetTable 'SET' SetClauseList WhereClause_EDIT
- | 'UPDATE' TargetTable 'SET' SetClauseList OptionalWhereClause 'CURSOR'
+ : 'UPDATE' TargetTable_EDIT 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause
+ | 'UPDATE' TargetTable 'SET' SetClauseList_EDIT OptionalFromJoinedTable OptionalWhereClause
+ | 'UPDATE' TargetTable 'SET' SetClauseList FromJoinedTable_EDIT OptionalWhereClause
+ | 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable WhereClause_EDIT
+ | 'UPDATE' TargetTable 'SET' SetClauseList OptionalFromJoinedTable OptionalWhereClause 'CURSOR'
    {
-     if (!$5) {
+     if (parser.isImpala() && !$6 && !$5) {
+       parser.suggestKeywords([{ value: 'FROM', weight: 2 }, { value: 'WHERE', weight: 1 }]);
+     } else if (parser.isImpala() && !$6 && $5) {
+       var keywords = [{ value: 'FULL JOIN', weight: 2 }, { value: 'FULL OUTER JOIN', weight: 2 }, { value: 'JOIN', weight: 2 }, { value: 'LEFT JOIN', weight: 2 }, { value: 'LEFT OUTER JOIN', weight: 2 }, { value: 'RIGHT JOIN', weight: 2 }, { value: 'RIGHT OUTER JOIN', weight: 2 }, { value: 'INNER JOIN', weight: 2 },  { value: 'LEFT ANTI JOIN', weight: 2 }, { value: 'LEFT SEMI JOIN', weight: 2 }, { value: 'RIGHT ANTI JOIN', weight: 2 }, { value: 'RIGHT SEMI JOIN', weight: 2 }, { value: 'WHERE', weight: 1 }];
+       if ($5.suggestJoinConditions) {
+         parser.suggestJoinConditions($5.suggestJoinConditions);
+       }
+       if ($5.suggestJoins) {
+         parser.suggestJoins($5.suggestJoins);
+       }
+       if ($5.suggestKeywords) {
+         keywords = keywords.concat(parser.createWeightedKeywords($5.suggestKeywords, 3));
+       }
+       parser.suggestKeywords(keywords);
+     } else if (!$6) {
        parser.suggestKeywords([ 'WHERE' ]);
      }
    }
@@ -106,4 +121,18 @@ UpdateSource
 
 UpdateSource_EDIT
  : ValueExpression_EDIT
- ;
+ ;
+
+OptionalFromJoinedTable
+ :
+ | 'FROM' TableReference  -> $2
+ ;
+
+FromJoinedTable_EDIT
+ : 'FROM' 'CURSOR'
+   {
+     parser.suggestTables();
+     parser.suggestDatabases({ appendDot: true });
+   }
+ | 'FROM' TableReference_EDIT
+ ;

+ 71 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecUpdate.js

@@ -56,9 +56,9 @@
       assertAutoComplete({
         beforeCursor: 'UPDATE bar SET id=1, foo=2 ',
         afterCursor: '',
+        containsKeywords: ['WHERE'],
         expectedResult: {
           lowerCase: false,
-          suggestKeywords: ['WHERE'],
           locations: [
             { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 27 } },
             { type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11}, identifierChain: [{ name: 'bar'}] },
@@ -231,5 +231,75 @@
         }
       });
     });
+
+    describe('Impala specific', function () {
+      it('should suggest keywords for "UPDATE bar.foo SET bla = \'foo\' |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'UPDATE bar.foo SET bla = \'foo\' ',
+          afterCursor: '',
+          dialect: 'impala',
+          containsKeywords: ['FROM', 'WHERE'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest tables for "UPDATE bar.foo SET bla = \'foo\' FROM |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'UPDATE bar.foo SET bla = \'foo\' FROM ',
+          afterCursor: '',
+          dialect: 'impala',
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: {},
+            suggestDatabases: {
+              appendDot: true
+            }
+          }
+        });
+      });
+
+      it('should suggest keywords for "UPDATE bar.foo SET bla = \'foo\' FROM boo |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'UPDATE bar.foo SET bla = \'foo\' FROM boo ',
+          afterCursor: '',
+          dialect: 'impala',
+          containsKeywords: ['JOIN'],
+          expectedResult: {
+            lowerCase: false,
+            suggestJoins: { prependJoin: true, tables: [{ identifierChain: [{ name: 'boo' }] }] }
+          }
+        });
+      });
+
+      it('should suggest keywords for "UPDATE bar.foo SET bla = \'foo\' FROM boo JOIN |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'UPDATE bar.foo SET bla = \'foo\' FROM boo JOIN ',
+          afterCursor: '',
+          dialect: 'impala',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['[BROADCAST]', '[SHUFFLE]'],
+            suggestJoins: { prependJoin: false, joinType: 'JOIN', tables: [{ identifierChain: [{ name: 'boo' }] }] },
+            suggestTables: {  },
+            suggestDatabases: { appendDot: true }
+          }
+        });
+      });
+
+      it('should suggest keywords for "UPDATE bar.foo SET bla = \'foo\' FROM boo JOIN blaa |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'UPDATE bar.foo SET bla = \'foo\' FROM boo JOIN blaa ',
+          afterCursor: '',
+          dialect: 'impala',
+          containsKeywords: ['ON', 'JOIN'],
+          expectedResult: {
+            lowerCase: false,
+            suggestJoinConditions: { prependOn: true, tables: [{ identifierChain: [{ name: 'bar' }, { name: 'foo' }] }, { identifierChain: [{ name: 'boo' }] }, { identifierChain: [{ name: 'blaa' }] }] }
+          }
+        });
+      });
+    })
   });
 })();

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


Неке датотеке нису приказане због велике количине промена