Pārlūkot izejas kodu

HUE-6835 [autocomplete] Add completion for Impala DELETE statements

Johan Ahlen 8 gadi atpakaļ
vecāks
revīzija
0a0171f

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql.jisonlex

@@ -204,6 +204,7 @@
 <impala>'CREATE'                           { parser.determineCase(yytext); return '<impala>CREATE'; }
 <impala>'DATA'                             { return '<impala>DATA'; }
 <impala>'DATABASES'                        { return '<impala>DATABASES'; }
+<impala>'DELETE'                           { return '<impala>DELETE'; }
 <impala>'DELIMITED'                        { return '<impala>DELIMITED'; }
 <impala>'DESCRIBE'                         { parser.determineCase(yytext); return '<impala>DESCRIBE'; }
 <impala>'ESCAPED'                          { return '<impala>ESCAPED'; }

+ 43 - 4
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -23,11 +23,13 @@ DataDefinition_EDIT
  ;
 
 DataManipulation
- : DeleteStatement
+ : HiveDeleteStatement
+ | ImpalaDeleteStatement
  ;
 
 DataManipulation_EDIT
- : DeleteStatement_EDIT
+ : HiveDeleteStatement_EDIT
+ | ImpalaDeleteStatement_EDIT
  ;
 
 DropStatement
@@ -372,14 +374,14 @@ TruncateTableStatement_EDIT
    }
  ;
 
-DeleteStatement
+HiveDeleteStatement
  : '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier OptionalWhereClause
    {
      parser.addTablePrimary($3);
    }
  ;
 
-DeleteStatement_EDIT
+HiveDeleteStatement_EDIT
  : '<hive>DELETE' 'CURSOR'
    {
      parser.suggestKeywords(['FROM']);
@@ -402,3 +404,40 @@ DeleteStatement_EDIT
      parser.addTablePrimary($3);
    }
  ;
+
+ImpalaDeleteStatement
+ : '<impala>DELETE' 'FROM' TableReference OptionalWhereClause
+ ;
+
+ImpalaDeleteStatement_EDIT
+ : '<impala>DELETE' 'CURSOR'
+   {
+     parser.suggestKeywords(['FROM']);
+   }
+ | '<impala>DELETE' 'FROM' 'CURSOR'
+   {
+     parser.suggestTables();
+     parser.suggestDatabases({ appendDot: true });
+   }
+ | '<impala>DELETE' 'FROM' TableReference 'CURSOR' OptionalWhereClause
+   {
+     var keywords = [{ value: 'FULL JOIN', weight: 1 }, { value: 'FULL OUTER JOIN', weight: 1 }, { value: 'JOIN', weight: 1 }, { value: 'LEFT JOIN', weight: 1 }, { value: 'LEFT OUTER JOIN', weight: 1 }, { value: 'RIGHT JOIN', weight: 1 }, { value: 'RIGHT OUTER JOIN', weight: 1 }, { value: 'INNER JOIN', weight: 1 },  { value: 'LEFT ANTI JOIN', weight: 1 }, { value: 'LEFT SEMI JOIN', weight: 1 }, { value: 'RIGHT ANTI JOIN', weight: 1 }, { value: 'RIGHT SEMI JOIN', weight: 1 }];
+     if (!$5) {
+       keywords.push({ value: 'WHERE', weight: 3 });
+     }
+     if ($3.suggestJoinConditions) {
+       parser.suggestJoinConditions($3.suggestJoinConditions);
+     }
+     if ($3.suggestJoins) {
+       parser.suggestJoins($3.suggestJoins);
+     }
+     if ($3.suggestKeywords) {
+       keywords = keywords.concat(parser.createWeightedKeywords($3.suggestKeywords, 2));
+     }
+     if (keywords.length > 0) {
+       parser.suggestKeywords(keywords);
+     }
+   }
+ | '<impala>DELETE' 'FROM' TableReference_EDIT OptionalWhereClause
+ | '<impala>DELETE' 'FROM' TableReference WhereClause_EDIT
+ ;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison


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

@@ -407,7 +407,7 @@
           dialect: 'impala',
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['ALTER', 'COMPUTE', 'CREATE', 'DESCRIBE',
+            suggestKeywords: ['ALTER', 'COMPUTE', 'CREATE', 'DELETE', 'DESCRIBE',
               'DROP', 'EXPLAIN', 'GRANT', 'INSERT', 'INVALIDATE METADATA', 'LOAD', 'REFRESH',
               'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH']
           }

+ 247 - 104
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecDrop.js

@@ -90,127 +90,270 @@
     });
 
     describe('DELETE FROM', function () {
-      it('should handle "DELETE FROM boo.baa;|"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM boo.baa;',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          containsKeywords: ['SELECT'],
-          expectedResult: {
-            lowerCase: false
-          }
+      describe('Hive specific', function () {
+        it('should handle "DELETE FROM boo.baa;|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa;',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
         });
-      });
 
-      it('should handle "DELETE FROM boo.baa WHERE id < 1 AND bla IN (SELECT * FROM boo);|"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM boo.baa WHERE id < 1 AND bla IN (SELECT * FROM boo);',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          containsKeywords: ['SELECT'],
-          expectedResult: {
-            lowerCase: false
-          }
+        it('should handle "DELETE FROM boo.baa WHERE id < 1 AND bla IN (SELECT * FROM boo);|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa WHERE id < 1 AND bla IN (SELECT * FROM boo);',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
         });
-      });
 
-      it('should suggest keywords for "|"', function() {
-        assertAutoComplete({
-          beforeCursor: '',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          containsKeywords: ['DELETE'],
-          expectedResult: {
-            lowerCase: false
-          }
+        it('should suggest keywords for "|"', function() {
+          assertAutoComplete({
+            beforeCursor: '',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            containsKeywords: ['DELETE'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
         });
-      });
 
-      it('should suggest keywords for "DELETE |"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE ',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          expectedResult: {
-            lowerCase: false,
-            suggestKeywords: ['FROM']
-          }
+        it('should suggest keywords for "DELETE |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE ',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['FROM']
+            }
+          });
         });
-      });
 
-      it('should suggest tables for "DELETE FROM |"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM ',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          expectedResult: {
-            lowerCase: false,
-            suggestTables: {},
-            suggestDatabases: { appendDot: true }
-          }
+        it('should suggest tables for "DELETE FROM |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM ',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: {},
+              suggestDatabases: { appendDot: true }
+            }
+          });
         });
-      });
 
-      it('should suggest tables for "DELETE FROM db.|"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM db.',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          expectedResult: {
-            lowerCase: false,
-            suggestTables: { identifierChain: [{ name: 'db' }]}
-          }
+        it('should suggest tables for "DELETE FROM db.|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM db.',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: { identifierChain: [{ name: 'db' }]}
+            }
+          });
         });
-      });
 
-      it('should suggest keywords for "DELETE FROM boo.baa |"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM boo.baa ',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          expectedResult: {
-            lowerCase: false,
-            suggestKeywords: ['WHERE']
-          }
+        it('should suggest keywords for "DELETE FROM boo.baa |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa ',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['WHERE']
+            }
+          });
         });
-      });
 
-      it('should suggest columns for "DELETE FROM boo.baa WHERE |"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM boo.baa WHERE ',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          containsKeywords: ['EXISTS'],
-          expectedResult: {
-            lowerCase: false,
-            suggestFunctions: {},
-            suggestColumns: { tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
-          }
+        it('should suggest columns for "DELETE FROM boo.baa WHERE |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa WHERE ',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            containsKeywords: ['EXISTS'],
+            expectedResult: {
+              lowerCase: false,
+              suggestFunctions: {},
+              suggestColumns: { tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
+            }
+          });
+        });
+
+        it('should suggest columns for "DELETE FROM boo.baa WHERE id > |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa WHERE id > ',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            containsKeywords: ['EXISTS'],
+            expectedResult: {
+              lowerCase: false,
+              suggestValues: {},
+              suggestFunctions: { types: ['COLREF'] },
+              colRef: { identifierChain: [{ name: 'boo'}, { name: 'baa' }, { name: 'id' }] },
+              suggestColumns: { types: ['COLREF'], tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
+            }
+          });
         });
       });
 
-      it('should suggest columns for "DELETE FROM boo.baa WHERE id > |"', function() {
-        assertAutoComplete({
-          beforeCursor: 'DELETE FROM boo.baa WHERE id > ',
-          afterCursor: '',
-          dialect: 'hive',
-          noErrors:true,
-          containsKeywords: ['EXISTS'],
-          expectedResult: {
-            lowerCase: false,
-            suggestValues: {},
-            suggestFunctions: { types: ['COLREF'] },
-            colRef: { identifierChain: [{ name: 'boo'}, { name: 'baa' }, { name: 'id' }] },
-            suggestColumns: { types: ['COLREF'], tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
-          }
+      describe('Impala specific', function () {
+        it('should handle "DELETE FROM boo.baa;|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa;',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should handle "DELETE FROM boo.baa WHERE id < 1 AND bla IN (SELECT * FROM boo);|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa WHERE id < 1 AND bla IN (SELECT * FROM boo);',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should handle "DELETE FROM boo.baa b JOIN bla.ble c ON b.foo = c.bar WHERE b.id < 1 AND c.id IN (SELECT * FROM boo);|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa b JOIN bla.ble c ON b.foo = c.bar WHERE b.id < 1 AND c.id IN (SELECT * FROM boo);',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "|"', function() {
+          assertAutoComplete({
+            beforeCursor: '',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            containsKeywords: ['DELETE'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DELETE |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE ',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['FROM']
+            }
+          });
+        });
+
+        it('should suggest tables for "DELETE FROM |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM ',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: {},
+              suggestDatabases: { appendDot: true }
+            }
+          });
+        });
+
+        it('should suggest tables for "DELETE FROM db.|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM db.',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: { identifierChain: [{ name: 'db' }]}
+            }
+          });
+        });
+
+        it('should suggest keywords for "DELETE FROM boo.baa |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa ',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            containsKeywords: ['WHERE', 'AS', 'LEFT ANTI JOIN'],
+            expectedResult: {
+              lowerCase: false,
+              suggestJoins: { prependJoin: true, tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
+            }
+          });
+        });
+
+        it('should suggest columns for "DELETE FROM boo.baa WHERE |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa WHERE ',
+            afterCursor: '',
+            dialect: 'impala',
+            noErrors:true,
+            containsKeywords: ['EXISTS'],
+            expectedResult: {
+              lowerCase: false,
+              suggestFunctions: {},
+              suggestColumns: { tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] },
+              suggestFilters: { tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
+            }
+          });
+        });
+
+        it('should suggest columns for "DELETE FROM boo.baa WHERE id > |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DELETE FROM boo.baa WHERE id > ',
+            afterCursor: '',
+            dialect: 'hive',
+            noErrors:true,
+            containsKeywords: ['EXISTS'],
+            expectedResult: {
+              lowerCase: false,
+              suggestValues: {},
+              suggestFunctions: { types: ['COLREF'] },
+              colRef: { identifierChain: [{ name: 'boo'}, { name: 'baa' }, { name: 'id' }] },
+              suggestColumns: { types: ['COLREF'], tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
+            }
+          });
         });
       });
     });

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

@@ -116,7 +116,7 @@
       it('should suggest expected words for "SLELECT "', function() {
         var result = sqlSyntaxParser.parseSyntax('SLELECT ', '', 'impala');
         expect(result).toBeTruthy();
-        expect(expectedToStrings(result.expected)).toEqual(['SELECT', 'SET', 'ALTER', 'INSERT', 'CREATE', 'EXPLAIN', 'GRANT', 'LOAD', 'REFRESH', 'REVOKE', 'SHOW', 'USE', 'COMPUTE', 'DROP', 'FROM', 'TRUNCATE', 'UPDATE', 'WITH', 'DESCRIBE', 'INVALIDATE']);
+        expect(expectedToStrings(result.expected)).toEqual(['SELECT', 'DELETE', 'SET', 'ALTER', 'INSERT', 'CREATE', 'EXPLAIN', 'GRANT', 'LOAD', 'REFRESH', 'REVOKE', 'SHOW', 'USE', 'COMPUTE', 'DROP', 'FROM', 'TRUNCATE', 'UPDATE', 'WITH', 'DESCRIBE', 'INVALIDATE']);
       });
     })
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


+ 1 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -1056,7 +1056,7 @@ var SqlParseSupport = (function () {
       }
 
       if (parser.isImpala()) {
-        keywords = keywords.concat(['COMPUTE', 'INVALIDATE METADATA', 'LOAD', 'REFRESH']);
+        keywords = keywords.concat(['COMPUTE', 'DELETE', 'INVALIDATE METADATA', 'LOAD', 'REFRESH']);
       }
 
       parser.suggestKeywords(keywords);

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels