浏览代码

HUE-6958 [autocomplete] Update autocomplete for Hive CREATE TABLE statements

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

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

@@ -32,8 +32,10 @@
 <hive>'AS'                                 { return '<hive>AS'; }
 <hive>'AUTHORIZATION'                      { return '<hive>AUTHORIZATION'; }
 <hive>'BINARY'                             { return '<hive>BINARY'; }
+<hive>'CACHE'                              { return '<hive>CACHE'; }
 <hive>'COLUMN'                             { return '<hive>COLUMN'; }
 <hive>'CONF'                               { return '<hive>CONF'; }
+<hive>'CONSTRAINT'                         { return '<hive>CONSTRAINT'; }
 <hive>'CREATE'                             { parser.determineCase(yytext); return '<hive>CREATE'; }
 <hive>'CUBE'                               { return '<hive>CUBE'; }
 <hive>'CURRENT'                            { return '<hive>CURRENT'; }
@@ -43,6 +45,7 @@
 <hive>'EXTENDED'                           { return '<hive>EXTENDED'; }
 <hive>'EXTERNAL'                           { return '<hive>EXTERNAL'; }
 <hive>'FOR'                                { return '<hive>FOR'; }
+<hive>'FOREIGN'                            { return '<hive>FOREIGN'; }
 <hive>'FUNCTION'                           { return '<hive>FUNCTION'; }
 <hive>'GRANT'                              { return '<hive>GRANT'; }
 <hive>'GROUPING'                           { return '<hive>GROUPING'; }
@@ -55,6 +58,8 @@
 <hive>'NONE'                               { return '<hive>NONE'; }
 <hive>'OF'                                 { return '<hive>OF'; }
 <hive>'OUT'                                { return '<hive>OUT'; }
+<hive>'PRIMARY'                            { return '<hive>PRIMARY'; }
+<hive>'REFERENCES'                         { return '<hive>REFERENCES'; }
 <hive>'REVOKE'                             { return '<hive>REVOKE'; }
 <hive>'ROLLUP'                             { return '<hive>ROLLUP'; }
 <hive>'TABLE'                              { return '<hive>TABLE'; }
@@ -72,7 +77,6 @@
 <hive>'AVRO'                               { return '<hive>AVRO'; }
 <hive>'BUCKET'                             { return '<hive>BUCKET'; }
 <hive>'BUCKETS'                            { return '<hive>BUCKETS'; }
-<hive>'CACHE'                              { return '<hive>CACHE'; }
 <hive>'CASCADE'                            { return '<hive>CASCADE'; }
 <hive>'CHANGE'                             { return '<hive>CHANGE'; }
 <hive>'CLUSTER'                            { return '<hive>CLUSTER'; }
@@ -119,6 +123,7 @@
 <hive>'INPUTFORMAT'                        { return '<hive>INPUTFORMAT'; }
 <hive>'ITEMS'                              { return '<hive>ITEMS'; }
 <hive>'JAR'                                { return '<hive>JAR'; }
+<hive>'KEY'                                { return '<hive>KEY'; }
 <hive>'KEYS'                               { return '<hive>KEYS'; }
 <hive>'LINES'                              { return '<hive>LINES'; }
 <hive>'LOAD'                               { parser.determineCase(yytext); return '<hive>LOAD'; }
@@ -130,6 +135,7 @@
 <hive>'MONTH'                              { return '<hive>MONTH'; }
 <hive>'MSCK'                               { return '<hive>MSCK'; }
 <hive>'NOSCAN'                             { return '<hive>NOSCAN'; }
+<hive>'NOVALIDATE'                         { return '<hive>NOVALIDATE'; }
 <hive>'NO_DROP'                            { return '<hive>NO_DROP'; }
 <hive>'OFFLINE'                            { return '<hive>OFFLINE'; }
 <hive>'ORC'                                { return '<hive>ORC'; }

+ 105 - 8
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_create.jison

@@ -289,30 +289,32 @@ OptionalColumnSpecificationsOrLike_EDIT
 
 ParenthesizedColumnSpecificationList
  : '(' ColumnSpecificationList ')'
+ | '(' ColumnSpecificationList ',' ConstraintSpecification ')'
  ;
 
 ParenthesizedColumnSpecificationList_EDIT
  : '(' ColumnSpecificationList_EDIT RightParenthesisOrError
+ | '(' ColumnSpecificationList ',' ConstraintSpecification_EDIT RightParenthesisOrError
+ | '(' ColumnSpecificationList ',' 'CURSOR' RightParenthesisOrError
+   {
+     if (parser.isImpala()) {
+       parser.suggestKeywords(['PRIMARY KEY']);
+     } else if (parser.isHive()) {
+       parser.suggestKeywords([{ value: 'PRIMARY KEY', weight: 2 }, { value: 'CONSTRAINT', weight: 1 }]);
+     }
+   }
  ;
 
 ColumnSpecificationList
  : ColumnSpecification
- | ColumnSpecificationList ',' ImpalaPrimaryKeySpecification                              -> $3
  | ColumnSpecificationList ',' ColumnSpecification                                        -> $3
  ;
 
 ColumnSpecificationList_EDIT
  : ColumnSpecification_EDIT
  | ColumnSpecification_EDIT ',' ColumnSpecificationList
- | ColumnSpecificationList ',' ImpalaPrimaryKeySpecification_EDIT
  | ColumnSpecificationList ',' ColumnSpecification_EDIT
  | ColumnSpecificationList ',' ColumnSpecification_EDIT ',' ColumnSpecificationList
- | ColumnSpecificationList ',' 'CURSOR'
-   {
-     if (parser.isImpala()) {
-       parser.suggestKeywords(['PRIMARY KEY']);
-     }
-   }
  | ColumnSpecification 'CURSOR'
    {
      parser.checkForKeywords($1);
@@ -574,6 +576,90 @@ GreaterThanOrError
  | error
  ;
 
+ConstraintSpecification
+ : ImpalaPrimaryKeySpecification
+ | HivePrimaryKeySpecification
+ | HiveForeignKeySpecification
+ | HivePrimaryKeySpecification ',' HiveForeignKeySpecification
+ ;
+
+ConstraintSpecification_EDIT
+ : ImpalaPrimaryKeySpecification_EDIT
+ | HivePrimaryKeySpecification_EDIT
+ | HivePrimaryKeySpecification ',' 'CURSOR'
+   {
+     parser.suggestKeywords(['CONSTRAINT']);
+   }
+ | HivePrimaryKeySpecification ',' HiveForeignKeySpecification_EDIT
+ | HivePrimaryKeySpecification_EDIT ',' HiveForeignKeySpecification
+ | HiveForeignKeySpecification_EDIT
+ | 'CURSOR' HiveForeignKeySpecification
+   {
+     parser.suggestKeywords(['PRIMARY KEY']);
+   }
+ ;
+
+HivePrimaryKeySpecification
+ : HivePrimaryKey ParenthesizedColumnList '<hive>DISABLE' '<hive>NOVALIDATE'
+ ;
+
+HivePrimaryKeySpecification_EDIT
+ : HivePrimaryKey_EDIT
+ | HivePrimaryKey ParenthesizedColumnList_EDIT
+ | HivePrimaryKey ParenthesizedColumnList 'CURSOR'
+   {
+     parser.suggestKeywords(['DISABLE NOVALIDATE']);
+   }
+ | HivePrimaryKey ParenthesizedColumnList '<hive>DISABLE' 'CURSOR'
+   {
+     parser.suggestKeywords(['NOVALIDATE']);
+   }
+ | HivePrimaryKey ParenthesizedColumnList_EDIT '<hive>DISABLE' '<hive>NOVALIDATE'
+ ;
+
+HiveForeignKeySpecification
+ : '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList '<hive>REFERENCES' SchemaQualifiedTableIdentifier ParenthesizedColumnList '<hive>DISABLE' '<hive>NOVALIDATE'
+   {
+     parser.addTablePrimary($7);
+   }
+ ;
+
+HiveForeignKeySpecification_EDIT
+ : '<hive>CONSTRAINT' RegularOrBacktickedIdentifier 'CURSOR'
+   {
+     parser.suggestKeywords(['FOREIGN KEY']);
+   }
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' 'CURSOR'
+   {
+     parser.suggestKeywords(['KEY']);
+   }
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList_EDIT
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList 'CURSOR'
+   {
+     parser.suggestKeywords(['REFERENCES']);
+   }
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList '<hive>REFERENCES' 'CURSOR'
+   {
+     parser.suggestTables();
+     parser.suggestDatabases({ appendDot: true });
+   }
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList '<hive>REFERENCES' SchemaQualifiedTableIdentifier_EDIT
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList '<hive>REFERENCES' SchemaQualifiedTableIdentifier ParenthesizedColumnList_EDIT
+   {
+     parser.addTablePrimary($7);
+   }
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList '<hive>REFERENCES' SchemaQualifiedTableIdentifier ParenthesizedColumnList 'CURSOR'
+   {
+     parser.addTablePrimary($7);
+     parser.suggestKeywords(['DISABLE NOVALIDATE']);
+   }
+ | '<hive>CONSTRAINT' RegularOrBacktickedIdentifier '<hive>FOREIGN' '<hive>KEY' ParenthesizedColumnList '<hive>REFERENCES' SchemaQualifiedTableIdentifier ParenthesizedColumnList '<hive>DISABLE' 'CURSOR'
+   {
+     parser.addTablePrimary($7);
+     parser.suggestKeywords(['NOVALIDATE']);
+   }
+ ;
+
 ImpalaPrimaryKeySpecification
  : ImpalaPrimaryKey ParenthesizedColumnList
  ;
@@ -595,6 +681,17 @@ ImpalaPrimaryKey_EDIT
    }
  ;
 
+HivePrimaryKey
+ : '<hive>PRIMARY' '<hive>KEY'
+ ;
+
+HivePrimaryKey_EDIT
+ : '<hive>PRIMARY' 'CURSOR'
+   {
+     parser.suggestKeywords(['KEY']);
+   }
+ ;
+
 OptionalPartitionedBy
  :
  | PartitionedBy

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


+ 179 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecCreate.js

@@ -1971,6 +1971,40 @@
       });
 
       describe('Hive specific', function () {
+        it('should handle "CREATE TEMPORARY EXTERNAL TABLE IF NOT EXISTS db.tbl (id INT, col VARCHAR, ' +
+          'bla DOUBLE PRECISION, PRIMARY KEY (id, col) DISABLE NOVALIDATE, CONSTRAINT cnstrnt FOREIGN KEY (id, bla) ' +
+          'REFERENCES sometbl (id, ble) DISABLE NOVALIDATE) COMMENT \'table comment\';|"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE TEMPORARY EXTERNAL TABLE IF NOT EXISTS db.tbl (id INT, col VARCHAR, ' +
+            'bla DOUBLE PRECISION, PRIMARY KEY (id, col) DISABLE NOVALIDATE, CONSTRAINT cnstrnt FOREIGN KEY (id, bla) ' +
+            'REFERENCES sometbl (id, ble) DISABLE NOVALIDATE) COMMENT \'table comment\';',
+            noErrors: true,
+            afterCursor: '',
+            dialect: 'hive',
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should handle "CREATE TEMPORARY EXTERNAL TABLE IF NOT EXISTS db.tbl (id INT, col VARCHAR, ' +
+          'bla DOUBLE PRECISION, CONSTRAINT cnstrnt FOREIGN KEY (id, bla) ' +
+          'REFERENCES sometbl (id, ble) DISABLE NOVALIDATE) COMMENT \'table comment\';|"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE TEMPORARY EXTERNAL TABLE IF NOT EXISTS db.tbl (id INT, col VARCHAR, ' +
+            'bla DOUBLE PRECISION, CONSTRAINT cnstrnt FOREIGN KEY (id, bla) ' +
+            'REFERENCES sometbl (id, ble) DISABLE NOVALIDATE) COMMENT \'table comment\';',
+            noErrors: true,
+            afterCursor: '',
+            dialect: 'hive',
+            containsKeywords: ['SELECT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
         it('should suggest keywords for "CREATE EXTERNAL |"', function () {
           assertAutoComplete({
             beforeCursor: 'CREATE EXTERNAL ',
@@ -2043,6 +2077,151 @@
           });
         });
 
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['PRIMARY KEY', 'CONSTRAINT']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['KEY']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['DISABLE NOVALIDATE']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['NOVALIDATE']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['CONSTRAINT']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['FOREIGN KEY']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['KEY']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['REFERENCES']
+            }
+          });
+        });
+
+        it('should suggest tables for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestTables: {},
+              suggestDatabases: { appendDot: true }
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES sometbl(boo) |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES sometbl(boo) ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['DISABLE NOVALIDATE']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES sometbl(boo) DISABLE |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, PRIMARY KEY (id) DISABLE NOVALIDATE, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES sometbl(boo) DISABLE ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['NOVALIDATE']
+            }
+          });
+        });
+
+        it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES sometbl(boo) DISABLE |"', function () {
+          assertAutoComplete({
+            beforeCursor: 'CREATE EXTERNAL TABLE foo (id int, CONSTRAINT boo FOREIGN KEY (bla) REFERENCES sometbl(boo) DISABLE ',
+            afterCursor: '',
+            dialect: 'hive',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['NOVALIDATE']
+            }
+          });
+        });
+
         it('should suggest keywords for "CREATE EXTERNAL TABLE foo (id int) |"', function () {
           assertAutoComplete({
             beforeCursor: 'CREATE EXTERNAL TABLE foo (id int) ',

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


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


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