Procházet zdrojové kódy

HUE-4584 [editor] The new autocompleter should support DELETE

Johan Ahlen před 9 roky
rodič
revize
a2b0c25045

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

@@ -39,6 +39,7 @@
 <hive>'CUBE'                               { return '<hive>CUBE'; }
 <hive>'CURRENT'                            { return '<hive>CURRENT'; }
 <hive>'DATE'                               { return '<hive>DATE'; }
+<hive>'DELETE'                             { determineCase(yytext); return '<hive>DELETE'; }
 <hive>'DESCRIBE'                           { determineCase(yytext); return '<hive>DESCRIBE'; }
 <hive>'EXTENDED'                           { return '<hive>EXTENDED'; }
 <hive>'EXTERNAL'                           { return '<hive>EXTERNAL'; }

+ 40 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -22,6 +22,14 @@ DataDefinition_EDIT
  : DropStatement_EDIT
  ;
 
+DataManipulation
+ : DeleteStatement
+ ;
+
+DataManipulation_EDIT
+ : DeleteStatement_EDIT
+ ;
+
 DropStatement
  : DropDatabaseStatement
  | DropFunctionStatement
@@ -362,4 +370,35 @@ TruncateTableStatement_EDIT
    {
      addTablePrimary($3);
    }
- ;
+ ;
+
+DeleteStatement
+ : '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier OptionalWhereClause
+   {
+     addTablePrimary($3);
+   }
+ ;
+
+DeleteStatement_EDIT
+ : '<hive>DELETE' 'CURSOR'
+   {
+     suggestKeywords(['FROM']);
+   }
+ | '<hive>DELETE' 'FROM' 'CURSOR'
+   {
+     suggestTables();
+     suggestDatabases({ appendDot: true });
+   }
+ | '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier 'CURSOR' OptionalWhereClause
+   {
+     addTablePrimary($3);
+     if (!$5) {
+       suggestKeywords(['WHERE']);
+     }
+   }
+ | '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier_EDIT OptionalWhereClause
+ | '<hive>DELETE' 'FROM' SchemaQualifiedTableIdentifier WhereClause_EDIT
+   {
+     addTablePrimary($3);
+   }
+ ;

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js


+ 2 - 2
desktop/core/src/desktop/static/desktop/js/autocomplete/sql_support.js

@@ -743,14 +743,14 @@ var getKeywordsForOptionalsLR = function (optionals, keywords, override) {
 };
 
 var suggestDdlAndDmlKeywords = function (extraKeywords) {
-  var keywords = ['ALTER', 'CREATE', 'DELETE', 'DESCRIBE', 'DROP', 'INSERT', 'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH'];
+  var keywords = ['ALTER', 'CREATE', 'DESCRIBE', 'DROP', 'INSERT', 'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH'];
 
   if (extraKeywords) {
     keywords = keywords.concat(extraKeywords);
   }
 
   if (isHive()) {
-    keywords = keywords.concat(['ANALYZE', 'EXPORT', 'IMPORT', 'LOAD', 'MSCK', 'RELOAD FUNCTION', 'RESET']);
+    keywords = keywords.concat(['ANALYZE', 'DELETE', 'EXPORT', 'IMPORT', 'LOAD', 'MSCK', 'RELOAD FUNCTION', 'RESET']);
   }
 
   if (isImpala()) {

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

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

+ 131 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecDrop.js

@@ -93,6 +93,137 @@ define([
       });
     });
 
+    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'],
+          hasLocations: true,
+          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'],
+          hasLocations: true,
+          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 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 keywords for "DELETE FROM boo.baa |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DELETE FROM boo.baa ',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors:true,
+          hasLocations: 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,
+          hasLocations: 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,
+          hasLocations: true,
+          containsKeywords: ['EXISTS'],
+          expectedResult: {
+            lowerCase: false,
+            suggestValues: true,
+            suggestFunctions: { types: ['COLREF'] },
+            colRef: { identifierChain: [{ name: 'boo'}, { name: 'baa' }, { name: 'id' }] },
+            suggestColumns: { types: ['COLREF'], tables: [{ identifierChain: [{ name: 'boo' }, { name: 'baa' }] }] }
+          }
+        });
+      });
+    });
+
     describe('DROP DATABASE', function () {
       it('should suggest databases for "DROP DATABASE |"', function() {
         assertAutoComplete({

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

@@ -5779,7 +5779,7 @@ define([
         });
       });
 
-      xit('should suggest keywords for "SELECT * FROM boo |, baa', function () {
+      it('should suggest keywords for "SELECT * FROM boo |, baa', function () {
         assertAutoComplete({
           beforeCursor: 'SELECT * FROM boo ',
           afterCursor: ', baa',

+ 1 - 1
desktop/core/src/desktop/static/desktop/spec/autocompleterTestUtils.js

@@ -141,7 +141,7 @@ define([
       }
     },
     assertAutocomplete: function(testDefinition) {
-      var debug = true;
+      var debug = false;
       if (typeof testDefinition.dialect === 'undefined') {
         expect(sql.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor, testDefinition.dialect, sqlFunctions, debug)).toEqualDefinition(testDefinition);
         testDefinition.dialect = 'hive';

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů