Browse Source

HUE-4589 [editor] The new autocompleter should completely support COMPUTE and DROP STATS

Johan Ahlen 9 năm trước cách đây
mục cha
commit
06b3d06

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

@@ -181,6 +181,7 @@
 <impala>'COLUMN'                           { return '<impala>COLUMN'; }
 <impala>'COLUMNS'                          { return '<impala>COLUMNS'; }
 <impala>'COMMENT'                          { return '<impala>COMMENT'; }
+<impala>'COMPUTE'                          { determineCase(yytext); return '<impala>COMPUTE'; }
 <impala>'CREATE'                           { determineCase(yytext); return '<impala>CREATE'; }
 <impala>'DATA'                             { return '<impala>DATA'; }
 <impala>'DATABASES'                        { return '<impala>DATABASES'; }

+ 52 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_analyze.jison

@@ -18,12 +18,14 @@ DataDefinition
  : AnalyzeStatement
  | RefreshStatement
  | InvalidateStatement
+ | ComputeStatsStatement
  ;
 
 DataDefinition_EDIT
  : AnalyzeStatement_EDIT
  | RefreshStatement_EDIT
  | InvalidateStatement_EDIT
+ | ComputeStatsStatement_EDIT
  ;
 
 AnalyzeStatement
@@ -163,4 +165,54 @@ InvalidateStatement_EDIT
      suggestDatabases({ appendDot: true });
    }
  | '<impala>INVALIDATE' '<impala>METADATA' SchemaQualifiedTableIdentifier_EDIT
+ ;
+
+ComputeStatsStatement
+ : '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier
+   {
+     addTablePrimary($3);
+   }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     addTablePrimary($4);
+   }
+ ;
+
+ComputeStatsStatement_EDIT
+ : '<impala>COMPUTE' 'CURSOR'
+   {
+     suggestKeywords(['STATS', 'INCREMENTAL STATS']);
+   }
+ | '<impala>COMPUTE' '<impala>STATS' 'CURSOR'
+   {
+     suggestTables();
+     suggestDatabases({ appendDot: true });
+   }
+ | '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
+ | '<impala>COMPUTE' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     addTablePrimary($4);
+     suggestKeywords(['INCREMENTAL']);
+   }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' 'CURSOR'
+   {
+     suggestKeywords(['STATS']);
+   }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
+   {
+     suggestTables();
+     suggestDatabases({ appendDot: true });
+   }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier 'CURSOR' OptionalPartitionSpec
+   {
+     addTablePrimary($4);
+     if (!$6) {
+       suggestKeywords(['PARTITION']);
+     }
+   }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
+   {
+     addTablePrimary($4);
+   }
  ;

+ 52 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -26,6 +26,7 @@ DropStatement
  : DropDatabaseStatement
  | DropFunctionStatement
  | DropRoleStatement
+ | DropStatsStatement
  | DropTableStatement
  | DropIndexStatement
  | DropMacroStatement
@@ -36,6 +37,7 @@ DropStatement
 DropStatement_EDIT
  : DropDatabaseStatement_EDIT
  | DropFunctionStatement_EDIT
+ | DropStatsStatement_EDIT
  | DropTableStatement_EDIT
  | DropIndexStatement_EDIT
  | DropMacroStatement_EDIT
@@ -167,6 +169,56 @@ DropRoleStatement
  : 'DROP' AnyRole RegularIdentifier
  ;
 
+DropStatsStatement
+ : 'DROP' '<impala>STATS' SchemaQualifiedTableIdentifier
+   {
+     addTablePrimary($3);
+   }
+ | 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec
+   {
+     addTablePrimary($4);
+   }
+ ;
+
+DropStatsStatement_EDIT
+ : 'DROP' '<impala>STATS' 'CURSOR'
+   {
+     suggestTables();
+     suggestDatabases({ appendDot: true });
+   }
+ | 'DROP' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
+ | 'DROP' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier
+   {
+     addTablePrimary($4);
+     suggestKeywords(['INCREMENTAL']);
+   }
+ | 'DROP' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec
+   {
+     addTablePrimary($4);
+     suggestKeywords(['INCREMENTAL']);
+   }
+ | 'DROP' '<impala>INCREMENTAL' 'CURSOR'
+   {
+     suggestKeywords(['STATS']);
+   }
+ | 'DROP' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
+   {
+     suggestTables();
+     suggestDatabases({ appendDot: true });
+   }
+ | 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
+ | 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT PartitionSpec
+ | 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier 'CURSOR'
+   {
+     addTablePrimary($4);
+     suggestKeywords(['PARTITION']);
+   }
+ | 'DROP' '<impala>INCREMENTAL' '<impala>STATS' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
+   {
+     addTablePrimary($4);
+   }
+ ;
+
 DropTableStatement
  : 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier
    {

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js


+ 177 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecAnalyze.js

@@ -253,6 +253,183 @@ define([
       });
     });
 
+    describe('COMPUTE STATS', function () {
+      it('should handle "COMPUTE STATS bla.boo;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE STATS bla.boo;',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors: true,
+          hasLocations: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "COMPUTE INCREMENTAL STATS bla.boo;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL STATS bla.boo;',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors: true,
+          hasLocations: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "COMPUTE INCREMENTAL STATS bla.boo PARTITION (a=1, b = 2);|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL STATS bla.boo PARTITION (a=1, b = 2);',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors: true,
+          hasLocations: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest keywords for "|"', function() {
+        assertAutoComplete({
+          beforeCursor: '',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          containsKeywords: ['COMPUTE'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest keywords for "COMPUTE |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['INCREMENTAL STATS', 'STATS']
+          }
+        });
+      });
+
+      it('should suggest tables for "COMPUTE STATS |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE STATS ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true }
+          }
+        });
+      });
+
+      it('should suggest tables for "COMPUTE STATS db.|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE STATS db.',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: { identifierChain: [{ name: 'db' }]}
+          }
+        });
+      });
+
+      it('should suggest keywords for "COMPUTE INCREMENTAL |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['STATS']
+          }
+        });
+      });
+
+      it('should suggest tables for "COMPUTE INCREMENTAL STATS |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL STATS ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true }
+          }
+        });
+      });
+
+      it('should suggest tables for "COMPUTE INCREMENTAL STATS db.|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE STATS db.',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: { identifierChain: [{ name: 'db' }]}
+          }
+        });
+      });
+
+      it('should suggest keywords for "COMPUTE INCREMENTAL STATS db.tbl |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL STATS db.tbl ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['PARTITION']
+          }
+        });
+      });
+
+      it('should suggest columns for "COMPUTE INCREMENTAL STATS db.tbl PARTITION (|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL STATS db.tbl PARTITION (',
+          afterCursor: '',
+          dialect: 'impala',
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestColumns: { tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl' }]} ]}
+          }
+        });
+      });
+
+      it('should suggest columns for "COMPUTE INCREMENTAL STATS db.tbl PARTITION (bla = 1, |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL STATS db.tbl PARTITION (bla = 1, ',
+          afterCursor: '',
+          dialect: 'impala',
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestColumns: { tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl' }]} ]}
+          }
+        });
+      });
+    });
+
     describe('INVALIDATE METADATA', function () {
       it('should handle "INVALIDATE METADATA;|"', function() {
         assertAutoComplete({

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

@@ -406,6 +406,156 @@ define([
       });
     });
 
+    describe('DROP STATS', function () {
+      it('should handle "DROP STATS bla.boo;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP STATS bla.boo;',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors: true,
+          hasLocations: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "DROP INCREMENTAL STATS bla.boo PARTITION (a=1, b = 2);|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP INCREMENTAL STATS bla.boo PARTITION (a=1, b = 2);',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors: true,
+          hasLocations: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest keywords for "DROP |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          containsKeywords: ['INCREMENTAL STATS', 'STATS'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest tables for "DROP STATS |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP STATS ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true }
+          }
+        });
+      });
+
+      it('should suggest tables for "DROP STATS db.|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP STATS db.',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: { identifierChain: [{ name: 'db' }]}
+          }
+        });
+      });
+
+      it('should suggest keywords for "DROP INCREMENTAL |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP INCREMENTAL ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['STATS']
+          }
+        });
+      });
+
+      it('should suggest tables for "DROP INCREMENTAL STATS |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP INCREMENTAL STATS ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true }
+          }
+        });
+      });
+
+      it('should suggest tables for "DROP INCREMENTAL STATS db.|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP STATS db.',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: { identifierChain: [{ name: 'db' }]}
+          }
+        });
+      });
+
+      it('should suggest keywords for "DROP INCREMENTAL STATS db.tbl |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP INCREMENTAL STATS db.tbl ',
+          afterCursor: '',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['PARTITION']
+          }
+        });
+      });
+
+      it('should suggest columns for "DROP INCREMENTAL STATS db.tbl PARTITION (|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP INCREMENTAL STATS db.tbl PARTITION (',
+          afterCursor: '',
+          dialect: 'impala',
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestColumns: { tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl' }]} ]}
+          }
+        });
+      });
+
+      it('should suggest columns for "DROP INCREMENTAL STATS db.tbl PARTITION (bla = 1, |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP INCREMENTAL STATS db.tbl PARTITION (bla = 1, ',
+          afterCursor: '',
+          dialect: 'impala',
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestColumns: { tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl' }]} ]}
+          }
+        });
+      });
+    });
+
     describe('DROP TABLE', function () {
       it('should suggest tables for "DROP TABLE |"', function() {
         assertAutoComplete({

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

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

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác