Explorar o código

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

Johan Ahlen %!s(int64=9) %!d(string=hai) anos
pai
achega
c82ab28242

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

@@ -29,68 +29,75 @@ DataDefinition_EDIT
  ;
 
 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
- : 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);
-     $$ = { 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);
    }
+ | '<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
@@ -165,6 +172,11 @@ InvalidateStatement_EDIT
      suggestDatabases({ appendDot: true });
    }
  | '<impala>INVALIDATE' '<impala>METADATA' SchemaQualifiedTableIdentifier_EDIT
+ | '<impala>INVALIDATE' 'CURSOR' SchemaQualifiedTableIdentifier
+   {
+     addTablePrimary($3);
+     suggestKeywords(['METADATA']);
+   }
  ;
 
 ComputeStatsStatement
@@ -189,6 +201,11 @@ ComputeStatsStatement_EDIT
      suggestDatabases({ appendDot: true });
    }
  | '<impala>COMPUTE' '<impala>STATS' SchemaQualifiedTableIdentifier_EDIT
+ | '<impala>COMPUTE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     addTablePrimary($3);
+     suggestKeywords(['STATS', 'INCREMENTAL STATS']);
+   }
  | '<impala>COMPUTE' 'CURSOR' '<impala>STATS' SchemaQualifiedTableIdentifier OptionalPartitionSpec
    {
      addTablePrimary($4);
@@ -198,6 +215,11 @@ ComputeStatsStatement_EDIT
    {
      suggestKeywords(['STATS']);
    }
+ | '<impala>COMPUTE' '<impala>INCREMENTAL' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     addTablePrimary($4);
+     suggestKeywords(['STATS']);
+   }
  | '<impala>COMPUTE' '<impala>INCREMENTAL' '<impala>STATS' 'CURSOR'
    {
      suggestTables();

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 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()) {
-    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()) {
-    keywords = keywords.concat(['COMPUTE', 'INVALIDATE', 'LOAD', 'REFRESH']);
+    keywords = keywords.concat(['COMPUTE', 'INVALIDATE METADATA', 'LOAD', 'REFRESH']);
   }
 
   suggestKeywords(keywords);

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

@@ -410,7 +410,7 @@
           expectedResult: {
             lowerCase: false,
             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']
           }
         });
@@ -425,7 +425,7 @@
           dialect: 'hive',
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['ALTER', 'ANALYZE', 'CREATE', 'DELETE', 'DESCRIBE',
+            suggestKeywords: ['ALTER', 'ANALYZE TABLE', 'CREATE', 'DELETE', 'DESCRIBE',
               'DROP', 'EXPLAIN', 'EXPORT', 'FROM', 'IMPORT', 'INSERT', 'LOAD', 'MSCK',
               '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: '',
           dialect: 'hive',
           noErrors:true,
-          containsKeywords: ['ANALYZE'],
+          containsKeywords: ['ANALYZE TABLE'],
           expectedResult: {
             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() {
         assertAutoComplete({
           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() {
         assertAutoComplete({
           beforeCursor: 'COMPUTE STATS ',
@@ -460,7 +530,7 @@
           afterCursor: '',
           dialect: 'impala',
           noErrors:true,
-          containsKeywords: ['INVALIDATE'],
+          containsKeywords: ['INVALIDATE METADATA'],
           expectedResult: {
             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() {
         assertAutoComplete({
           beforeCursor: 'INVALIDATE METADATA ',

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio