瀏覽代碼

HUE-6958 [autocomplete] Add support for Hive ALTER DATABASE statements

Johan Ahlen 8 年之前
父節點
當前提交
28ab731

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

@@ -88,6 +88,7 @@
 <hive>'DATABASES'                          { return '<hive>DATABASES'; }
 <hive>'DAY'                                { return '<hive>DAY'; }
 <hive>'DAYOFWEEK'                          { return '<hive>DAYOFWEEK'; }
+<hive>'DBPROPERTIES'                       { return '<hive>DBPROPERTIES'; }
 <hive>'DEFERRED'                           { return '<hive>DEFERRED'; }
 <hive>'DEFINED'                            { return '<hive>DEFINED'; }
 <hive>'DELIMITED'                          { return '<hive>DELIMITED'; }
@@ -134,6 +135,7 @@
 <hive>'OUTPUTFORMAT'                       { return '<hive>OUTPUTFORMAT'; }
 <hive>'OVERWRITE'                          { return '<hive>OVERWRITE'; }
 <hive>OVERWRITE\s+DIRECTORY                { this.begin('hdfs'); return '<hive>OVERWRITE_DIRECTORY'; }
+<hive>'OWNER'                              { return '<hive>OWNER'; }
 <hive>'PARQUET'                            { return '<hive>PARQUET'; }
 <hive>'PARTITIONED'                        { return '<hive>PARTITIONED'; }
 <hive>'PARTITIONS'                         { return '<hive>PARTITIONS'; }

+ 38 - 3
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_alter.jison

@@ -23,7 +23,8 @@ DataDefinition_EDIT
  ;
 
 AlterStatement
- : AlterIndex
+ : AlterDatabase
+ | AlterIndex
  | AlterTable
  | AlterView
  | Msck
@@ -31,7 +32,8 @@ AlterStatement
  ;
 
 AlterStatement_EDIT
- : AlterIndex_EDIT
+ : AlterDatabase_EDIT
+ | AlterIndex_EDIT
  | AlterTable_EDIT
  | AlterView_EDIT
  | Msck_EDIT
@@ -39,13 +41,46 @@ AlterStatement_EDIT
  | 'ALTER' 'CURSOR'
    {
      if (parser.isHive()) {
-       parser.suggestKeywords(['INDEX', 'TABLE', 'VIEW']);
+       parser.suggestKeywords(['DATABASE', 'INDEX', 'SCHEMA', 'TABLE', 'VIEW']);
      } else {
        parser.suggestKeywords(['TABLE', 'VIEW']);
      }
    }
  ;
 
+AlterDatabase
+ : 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>DBPROPERTIES' ParenthesizedPropertyAssignmentList
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' HdfsLocation
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>OWNER' PrincipalSpecification
+ ;
+
+AlterDatabase_EDIT
+ : 'ALTER' DatabaseOrSchema 'CURSOR'
+   {
+     if (parser.isHive()) {
+      parser.suggestDatabases();
+     }
+   }
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'CURSOR'
+   {
+     if (parser.isHive()) {
+       parser.suggestKeywords(['SET DBPROPERTIES', 'SET LOCATION', 'SET OWNER']);
+     }
+   }
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' 'CURSOR'
+    {
+      if (parser.isHive()) {
+        parser.suggestKeywords(['DBPROPERTIES', 'LOCATION', 'OWNER']);
+      }
+    }
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' HdfsLocation_EDIT
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>OWNER' 'CURSOR'
+   {
+     parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
+   }
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>OWNER' PrincipalSpecification_EDIT
+ ;
+
 AlterIndex
  : 'ALTER' '<hive>INDEX' RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier OptionalPartitionSpec '<hive>REBUILD'
    {

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

@@ -130,8 +130,8 @@ OptionalHiveDbProperties
  ;
 
 HiveDbProperties
- : '<hive>WITH' 'DBPROPERTIES' ParenthesizedPropertyAssignmentList
- | '<hive>WITH' 'DBPROPERTIES'
+ : '<hive>WITH' '<hive>DBPROPERTIES' ParenthesizedPropertyAssignmentList
+ | '<hive>WITH' '<hive>DBPROPERTIES'
  | '<hive>WITH' 'CURSOR'
    {
      parser.suggestKeywords(['DBPROPERTIES']);

+ 6 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_grant.jison

@@ -285,6 +285,12 @@ PrincipalSpecification
  | '<hive>ROLE' RegularOrBacktickedIdentifier
  ;
 
+PrincipalSpecification_EDIT
+ : '<hive>USER' 'CURSOR'
+ | 'GROUP' 'CURSOR'
+ | '<hive>ROLE' 'CURSOR'
+ ;
+
 UserOrRoleList
  : RegularOrBacktickedIdentifier
  | UserOrRoleList ',' RegularOrBacktickedIdentifier

File diff suppressed because it is too large
+ 2 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison


+ 125 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecAlter.js

@@ -26,6 +26,131 @@
 
     var assertAutoComplete = SqlTestUtils.assertAutocomplete;
 
+    describe('ALTER DATABASE', function () {
+      it('should handle "ALTER DATABASE baa SET DBPROPERTIES (\'boo\'=1, \'baa\'=2);|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER DATABASE baa SET DBPROPERTIES (\'boo\'=1, \'baa\'=2);',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors:true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "ALTER SCHEMA baa SET OWNER ROLE boo;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER SCHEMA baa SET OWNER ROLE boo;',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors:true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "ALTER DATABASE baa SET LOCATION \'/baa/boo\';|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER DATABASE baa SET LOCATION \'/baa/boo\';',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors:true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest keywords for "ALTER |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER ',
+          afterCursor: '',
+          dialect: 'hive',
+          containsKeywords: ['DATABASE', 'SCHEMA'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest databases for "ALTER DATABASE |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER DATABASE ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestDatabases: {}
+          }
+        });
+      });
+
+      it('should suggest databases for "ALTER SCHEMA |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER SCHEMA ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestDatabases: {}
+          }
+        });
+      });
+
+      it('should suggest keywords for "ALTER SCHEMA boo |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER SCHEMA boo ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['SET DBPROPERTIES', 'SET LOCATION', 'SET OWNER']
+          }
+        });
+      });
+
+      it('should suggest keywords for "ALTER DATABASE boo SET |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER DATABASE boo SET ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['DBPROPERTIES', 'LOCATION', 'OWNER']
+          }
+        });
+      });
+
+      it('should suggest keywords for "ALTER DATABASE boo SET OWNER |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER DATABASE boo SET OWNER ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['GROUP', 'ROLE', 'USER']
+          }
+        });
+      });
+
+      it('should suggest hdfs for "ALTER DATABASE boo SET LOCATION \'/|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'ALTER DATABASE boo SET LOCATION \'/',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestHdfs: { path: '/' }
+          }
+        });
+      });
+    });
+
     describe('ALTER INDEX', function () {
       it('should handle "ALTER INDEX baa ON boo.ba PARTITION (bla=1) REBUILD;|"', function() {
         assertAutoComplete({

File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


Some files were not shown because too many files changed in this diff