Просмотр исходного кода

HUE-5459 [editor] Improve autocomplete keyword completion around ANALYZE, COMPUTE and INVALIDATE

Johan Ahlen 9 лет назад
Родитель
Сommit
c82ab28

+ 59 - 37
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_analyze.jison

@@ -29,68 +29,75 @@ DataDefinition_EDIT
  ;
  ;
 
 
 AnalyzeStatement
 AnalyzeStatement
- : AnalyzeTableLeftPart '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+ : '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+   {
+     addTablePrimary($3);
+   }
  ;
  ;
 
 
 AnalyzeStatement_EDIT
 AnalyzeStatement_EDIT
- : AnalyzeTableLeftPart_EDIT
- | AnalyzeTableLeftPart_EDIT '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
- | AnalyzeTableLeftPart 'CURSOR'
+ : '<hive>ANALYZE' 'CURSOR'
    {
    {
-     if (!$1.hasPartition) {
-       suggestKeywords([{ value: 'PARTITION', weight: 2 }, { value: 'COMPUTE STATISTICS', weight: 1 }]);
-     } else {
-       suggestKeywords(['COMPUTE STATISTICS']);
-     }
+     suggestKeywords(['TABLE']);
    }
    }
- | AnalyzeTableLeftPart '<hive>COMPUTE' 'CURSOR'
+ | '<hive>ANALYZE' '<hive>TABLE' 'CURSOR'
    {
    {
-     suggestKeywords(['STATISTICS']);
+     suggestTables({ onlyTables: true });
+     suggestDatabases({ appendDot: true });
    }
    }
- | AnalyzeTableLeftPart '<hive>COMPUTE' '<hive>STATISTICS' 'CURSOR' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
    {
    {
-     suggestKeywords(getKeywordsForOptionalsLR([$5, $6, $7], [{ value: 'FOR COLUMNS', weight: 3 }, { value: 'CACHE METADATA', weight: 2 }, { value: 'NOSCAN', weight: 1 }]));
+     if (parser.yy.result.suggestTables) {
+       parser.yy.result.suggestTables.onlyTables = true;
+     }
    }
    }
- | AnalyzeTableLeftPart '<hive>COMPUTE' '<hive>STATISTICS' ForColumns 'CURSOR' OptionalCacheMetadata OptionalNoscan
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
    {
    {
-     suggestKeywords(getKeywordsForOptionalsLR([$6, $7], [{ value: 'CACHE METADATA', weight: 2 }, { value: 'NOSCAN', weight: 1 }]));
+     addTablePrimary($3);
    }
    }
- | AnalyzeTableLeftPart '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns CacheMetadata 'CURSOR' OptionalNoscan
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
    {
    {
-     suggestKeywords(getKeywordsForOptionalsLR([$7], [{ value: 'NOSCAN', weight: 1 }]));
+     addTablePrimary($3);
+     if (!$4) {
+       suggestKeywords([{ value: 'PARTITION', weight: 2 }, { value: 'COMPUTE STATISTICS', weight: 1 }]);
+     } else {
+       suggestKeywords(['COMPUTE STATISTICS']);
+     }
    }
    }
- | AnalyzeTableLeftPart '<hive>COMPUTE' '<hive>STATISTICS' ForColumns_EDIT OptionalCacheMetadata OptionalNoscan
- | AnalyzeTableLeftPart '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns CacheMetadata_EDIT OptionalNoscan
- ;
-
-AnalyzeTableLeftPart
- : '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' 'CURSOR'
    {
    {
      addTablePrimary($3);
      addTablePrimary($3);
-     $$ = { hasPartition: $4 };
+     suggestKeywords(['STATISTICS']);
    }
    }
- ;
-
-AnalyzeTableLeftPart_EDIT
- : '<hive>ANALYZE' 'CURSOR'
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' 'CURSOR' OptionalForColumns OptionalCacheMetadata OptionalNoscan
    {
    {
-     suggestKeywords(['TABLE']);
+     addTablePrimary($3);
+     suggestKeywords(getKeywordsForOptionalsLR([$8, $9, $10], [{ value: 'FOR COLUMNS', weight: 3 }, { value: 'CACHE METADATA', weight: 2 }, { value: 'NOSCAN', weight: 1 }]));
    }
    }
- | '<hive>ANALYZE' '<hive>TABLE' 'CURSOR'
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' ForColumns 'CURSOR' OptionalCacheMetadata OptionalNoscan
    {
    {
-     suggestTables({ onlyTables: true });
-     suggestDatabases({ appendDot: true });
+     addTablePrimary($3);
+     suggestKeywords(getKeywordsForOptionalsLR([$9, $10], [{ value: 'CACHE METADATA', weight: 2 }, { value: 'NOSCAN', weight: 1 }]));
    }
    }
- | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns CacheMetadata 'CURSOR' OptionalNoscan
    {
    {
-     if (parser.yy.result.suggestTables) {
-       parser.yy.result.suggestTables.onlyTables = true;
-     }
+     addTablePrimary($3);
+     suggestKeywords(getKeywordsForOptionalsLR([$10], [{ value: 'NOSCAN', weight: 1 }]));
    }
    }
- | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | '<hive>ANALYZE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
    {
    {
+     suggestKeywords(['TABLE']);
      addTablePrimary($3);
      addTablePrimary($3);
    }
    }
+ | '<hive>ANALYZE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+   {
+     suggestKeywords(['TABLE']);
+     addTablePrimary($3);
+   }
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' ForColumns_EDIT OptionalCacheMetadata OptionalNoscan
+ | '<hive>ANALYZE' '<hive>TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>COMPUTE' '<hive>STATISTICS' OptionalForColumns CacheMetadata_EDIT OptionalNoscan
  ;
  ;
 
 
 OptionalForColumns
 OptionalForColumns
@@ -165,6 +172,11 @@ InvalidateStatement_EDIT
      suggestDatabases({ appendDot: true });
      suggestDatabases({ appendDot: true });
    }
    }
  | '<impala>INVALIDATE' '<impala>METADATA' SchemaQualifiedTableIdentifier_EDIT
  | '<impala>INVALIDATE' '<impala>METADATA' SchemaQualifiedTableIdentifier_EDIT
+ | '<impala>INVALIDATE' 'CURSOR' SchemaQualifiedTableIdentifier
+   {
+     addTablePrimary($3);
+     suggestKeywords(['METADATA']);
+   }
  ;
  ;
 
 
 ComputeStatsStatement
 ComputeStatsStatement
@@ -189,6 +201,11 @@ ComputeStatsStatement_EDIT
      suggestDatabases({ appendDot: true });
      suggestDatabases({ appendDot: true });
    }
    }
  | '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
  | '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
+ | '<impala>COMPUTE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     addTablePrimary($3);
+     suggestKeywords(['STATS', 'INCREMENTAL STATS']);
+   }
  | '<impala>COMPUTE' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
  | '<impala>COMPUTE' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
    {
    {
      addTablePrimary($4);
      addTablePrimary($4);
@@ -198,6 +215,11 @@ ComputeStatsStatement_EDIT
    {
    {
      suggestKeywords(['STATS']);
      suggestKeywords(['STATS']);
    }
    }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     addTablePrimary($4);
+     suggestKeywords(['STATS']);
+   }
  | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
  | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
    {
    {
      suggestTables();
      suggestTables();

Разница между файлами не показана из-за своего большого размера
+ 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

@@ -929,11 +929,11 @@ var suggestDdlAndDmlKeywords = function (extraKeywords) {
   }
   }
 
 
   if (isHive()) {
   if (isHive()) {
-    keywords = keywords.concat(['ANALYZE', 'DELETE', 'EXPORT', 'IMPORT', 'LOAD', 'MSCK', 'RELOAD FUNCTION', 'RESET']);
+    keywords = keywords.concat(['ANALYZE TABLE', 'DELETE', 'EXPORT', 'IMPORT', 'LOAD', 'MSCK', 'RELOAD FUNCTION', 'RESET']);
   }
   }
 
 
   if (isImpala()) {
   if (isImpala()) {
-    keywords = keywords.concat(['COMPUTE', 'INVALIDATE', 'LOAD', 'REFRESH']);
+    keywords = keywords.concat(['COMPUTE', 'INVALIDATE METADATA', 'LOAD', 'REFRESH']);
   }
   }
 
 
   suggestKeywords(keywords);
   suggestKeywords(keywords);

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

@@ -410,7 +410,7 @@
           expectedResult: {
           expectedResult: {
             lowerCase: false,
             lowerCase: false,
             suggestKeywords: ['ALTER', 'COMPUTE', 'CREATE', 'DESCRIBE',
             suggestKeywords: ['ALTER', 'COMPUTE', 'CREATE', 'DESCRIBE',
-              'DROP', 'EXPLAIN', 'INSERT', 'INVALIDATE', 'LOAD', 'REFRESH',
+              'DROP', 'EXPLAIN', 'INSERT', 'INVALIDATE METADATA', 'LOAD', 'REFRESH',
               'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH']
               'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH']
           }
           }
         });
         });
@@ -425,7 +425,7 @@
           dialect: 'hive',
           dialect: 'hive',
           expectedResult: {
           expectedResult: {
             lowerCase: false,
             lowerCase: false,
-            suggestKeywords: ['ALTER', 'ANALYZE', 'CREATE', 'DELETE', 'DESCRIBE',
+            suggestKeywords: ['ALTER', 'ANALYZE TABLE', 'CREATE', 'DELETE', 'DESCRIBE',
               'DROP', 'EXPLAIN', 'EXPORT', 'FROM', 'IMPORT', 'INSERT', 'LOAD', 'MSCK',
               'DROP', 'EXPLAIN', 'EXPORT', 'FROM', 'IMPORT', 'INSERT', 'LOAD', 'MSCK',
               'RELOAD FUNCTION', 'RESET', 'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH']
               'RELOAD FUNCTION', 'RESET', 'REVOKE', 'SELECT', 'SET', 'SHOW', 'TRUNCATE', 'UPDATE', 'USE', 'WITH']
           }
           }

+ 100 - 2
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecAnalyze.js

@@ -47,7 +47,7 @@
           afterCursor: '',
           afterCursor: '',
           dialect: 'hive',
           dialect: 'hive',
           noErrors:true,
           noErrors:true,
-          containsKeywords: ['ANALYZE'],
+          containsKeywords: ['ANALYZE TABLE'],
           expectedResult: {
           expectedResult: {
             lowerCase: false
             lowerCase: false
           }
           }
@@ -67,6 +67,34 @@
         });
         });
       });
       });
 
 
+      it('should suggest keywords for "analyze | tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'analyze ',
+          afterCursor: ' tbl',
+          dialect: 'hive',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: true,
+            suggestKeywords: ['TABLE']
+          }
+        });
+      });
+
+      it('should suggest keywords for "analyze tab| tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'analyze tab',
+          afterCursor: ' tbl',
+          dialect: 'hive',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: true,
+            suggestKeywords: ['TABLE']
+          }
+        });
+      });
+
       it('should suggest tables for "ANALYZE TABLE |"', function() {
       it('should suggest tables for "ANALYZE TABLE |"', function() {
         assertAutoComplete({
         assertAutoComplete({
           beforeCursor: 'ANALYZE TABLE ',
           beforeCursor: 'ANALYZE TABLE ',
@@ -318,6 +346,48 @@
         });
         });
       });
       });
 
 
+      it('should suggest keywords for "COMPUTE | tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE ',
+          afterCursor: ' tbl',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['INCREMENTAL STATS', 'STATS']
+          }
+        });
+      });
+
+      it('should suggest keywords for "COMPUTE foo| tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE foo',
+          afterCursor: ' tbl',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['INCREMENTAL STATS', 'STATS']
+          }
+        });
+      });
+
+      it('should suggest keywords for "COMPUTE INCREMENTAL | tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'COMPUTE INCREMENTAL ',
+          afterCursor: ' tbl',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['STATS']
+          }
+        });
+      });
+
       it('should suggest tables for "COMPUTE STATS |"', function() {
       it('should suggest tables for "COMPUTE STATS |"', function() {
         assertAutoComplete({
         assertAutoComplete({
           beforeCursor: 'COMPUTE STATS ',
           beforeCursor: 'COMPUTE STATS ',
@@ -460,7 +530,7 @@
           afterCursor: '',
           afterCursor: '',
           dialect: 'impala',
           dialect: 'impala',
           noErrors:true,
           noErrors:true,
-          containsKeywords: ['INVALIDATE'],
+          containsKeywords: ['INVALIDATE METADATA'],
           expectedResult: {
           expectedResult: {
             lowerCase: false
             lowerCase: false
           }
           }
@@ -480,6 +550,34 @@
         });
         });
       });
       });
 
 
+      it('should suggest keywords for "INVALIDATE | tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INVALIDATE ',
+          afterCursor: ' tbl',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['METADATA']
+          }
+        });
+      });
+
+      it('should suggest keywords for "INVALIDATE meta| tbl"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INVALIDATE meta',
+          afterCursor: ' tbl',
+          dialect: 'impala',
+          noErrors:true,
+          hasLocations: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['METADATA']
+          }
+        });
+      });
+
       it('should suggest tables for "INVALIDATE METADATA |"', function() {
       it('should suggest tables for "INVALIDATE METADATA |"', function() {
         assertAutoComplete({
         assertAutoComplete({
           beforeCursor: 'INVALIDATE METADATA ',
           beforeCursor: 'INVALIDATE METADATA ',

Некоторые файлы не были показаны из-за большого количества измененных файлов