浏览代码

HUE-6835 [autocomplete] Add support for the PURGE keyword in DROP TABLE statements

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

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

@@ -350,6 +350,7 @@
 'OUTER'                                    { return 'OUTER'; }
 'PARTITION'                                { return 'PARTITION'; }
 'PRECEDING'                                { return 'PRECEDING'; }
+'PURGE'                                    { return 'PURGE'; }
 'RANGE'                                    { return 'RANGE'; }
 'REGEXP'                                   { return 'REGEXP'; }
 'RIGHT'                                    { return 'RIGHT'; }

+ 12 - 5
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -230,7 +230,7 @@ DropStatsStatement_EDIT
  ;
 
 DropTableStatement
- : 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier
+ : 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge
    {
      parser.addTablePrimary($4);
    }
@@ -248,22 +248,29 @@ DropTableStatement_EDIT
        appendDot: true
      });
    }
- | 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT
+ | 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge
    {
      if (parser.yy.result.suggestTables) {
        parser.yy.result.suggestTables.onlyTables = true;
      }
    }
- | 'DROP' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
- | 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier 'CURSOR'
+ | 'DROP' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge
+ | 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR'
    {
      parser.addTablePrimary($4);
-     if (parser.isHive()) {
+     if (!$5) {
        parser.suggestKeywords(['PURGE']);
      }
    }
  ;
 
+OptionalPurge
+ :
+ | 'PURGE'
+ | '<hive>PURGE'
+ ;
+
+
 DropIndexStatement
  : 'DROP' '<hive>INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier
    {

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


+ 24 - 15
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecDrop.js

@@ -830,6 +830,18 @@
     });
 
     describe('DROP TABLE', function () {
+      it('should handle "DROP TABLE db.tbl PURGE;"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP TABLE db.tbl PURGE;',
+          afterCursor: '',
+          containsKeywords: ['SELECT'],
+          noErrors: true,
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
       it('should suggest tables for "DROP TABLE |"', function() {
         assertAutoComplete({
           beforeCursor: 'DROP TABLE ',
@@ -881,21 +893,18 @@
         });
       });
 
-      describe('Hive specific', function () {
-        it('should suggest keywords for "DROP TABLE foo |"', function() {
-          assertAutoComplete({
-            beforeCursor: 'DROP TABLE foo ',
-            afterCursor: '',
-            dialect: 'hive',
-            expectedResult: {
-              lowerCase: false,
-              suggestKeywords: ['PURGE'],
-              locations: [
-                { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 15 } },
-                {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15}, identifierChain: [{ name: 'foo' }]}
-              ]
-            }
-          });
+      it('should suggest keywords for "DROP TABLE foo |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP TABLE foo ',
+          afterCursor: '',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['PURGE'],
+            locations: [
+              { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 15 } },
+              {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15}, identifierChain: [{ name: 'foo' }]}
+            ]
+          }
         });
       });
     });

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


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


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