浏览代码

HUE-6835 [autocomplete] Improve autocomplete of Impala TRUNCATE statements

Johan Ahlen 8 年之前
父节点
当前提交
d0b8c7e

+ 21 - 9
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -351,9 +351,9 @@ DropViewStatement_EDIT
  ;
 
 TruncateTableStatement
- : 'TRUNCATE' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec
+ : 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec
    {
-     parser.addTablePrimary($3);
+     parser.addTablePrimary($4);
    }
  ;
 
@@ -362,23 +362,35 @@ TruncateTableStatement_EDIT
    {
      parser.suggestKeywords(['TABLE']);
    }
- | 'TRUNCATE' AnyTable 'CURSOR' OptionalPartitionSpec
+ | 'TRUNCATE' AnyTable OptionalIfExists 'CURSOR' OptionalPartitionSpec
    {
      parser.suggestTables();
      parser.suggestDatabases({ appendDot: true });
+     if (parser.isImpala() && !$3) {
+       parser.suggestKeywords(['IF EXISTS']);
+     }
    }
- | 'TRUNCATE' AnyTable SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
- | 'TRUNCATE' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
+ | 'TRUNCATE' AnyTable OptionalIfExists_EDIT OptionalPartitionSpec
+ | 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
+ | 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
    {
-     parser.addTablePrimary($3);
-     if (parser.isHive() && !$4) {
+     parser.addTablePrimary($4);
+     if (parser.isHive() && !$5) {
        parser.suggestKeywords(['PARTITION']);
      }
    }
- | 'TRUNCATE' AnyTable SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
    {
-     parser.addTablePrimary($3);
+     parser.addTablePrimary($4);
+   }
+ | 'TRUNCATE' AnyTable OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     parser.addTablePrimary($4);
+     if (parser.isImpala() && !$3) {
+       parser.suggestKeywords(['IF EXISTS']);
+     }
    }
+ | 'TRUNCATE' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec
  ;
 
 HiveDeleteStatement

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

@@ -1196,6 +1196,72 @@
           });
         });
       });
+
+      describe('Impala specific', function () {
+        it('should handle "TRUNCATE TABLE IF EXISTS baa.boo;"', function() {
+          assertAutoComplete({
+            beforeCursor: 'TRUNCATE TABLE IF EXISTS baa.boo;',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['SELECT'],
+            noErrors: true,
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest tables for "TRUNCATE TABLE |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'TRUNCATE TABLE ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: {},
+              suggestDatabases: { appendDot: true },
+              suggestKeywords: ['IF EXISTS']
+            }
+          });
+        });
+
+        it('should suggest keywords for "TRUNCATE TABLE IF |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'TRUNCATE TABLE IF ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['EXISTS']
+            }
+          });
+        });
+
+        it('should suggest tables for "TRUNCATE TABLE IF EXISTS |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'TRUNCATE TABLE IF EXISTS ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: {},
+              suggestDatabases: { appendDot: true }
+            }
+          });
+        });
+
+        it('should suggest keywords for "TRUNCATE TABLE | boo"', function() {
+          assertAutoComplete({
+            beforeCursor: 'TRUNCATE TABLE ',
+            afterCursor: ' boo',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['IF EXISTS']
+            }
+          });
+        });
+      })
     })
   });
 })();

文件差异内容过多而无法显示
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


文件差异内容过多而无法显示
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


部分文件因为文件数量过多而无法显示