Pārlūkot izejas kodu

HUE-9464 [editor] Add support for MANAGEDLOCATION in the Hive parser

Johan Ahlen 5 gadi atpakaļ
vecāks
revīzija
298d58ac70

+ 10 - 2
desktop/core/src/desktop/js/parse/jison/sql/hive/alter/alter_database.jison

@@ -35,6 +35,10 @@ AlterDatabase
     {
       parser.addDatabaseLocation(@3, [ { name: $3 } ]);
     }
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' ManagedLocation
+    {
+      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+    }
  ;
 
 AlterDatabase_EDIT
@@ -45,12 +49,12 @@ AlterDatabase_EDIT
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'CURSOR'
    {
      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
-     parser.suggestKeywords(['SET DBPROPERTIES', 'SET LOCATION', 'SET OWNER']);
+     parser.suggestKeywords(['SET DBPROPERTIES', 'SET LOCATION', 'SET MANAGEDLOCATION', 'SET OWNER']);
    }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' 'CURSOR'
     {
       parser.addDatabaseLocation(@3, [ { name: $3 } ]);
-      parser.suggestKeywords(['DBPROPERTIES', 'LOCATION', 'OWNER']);
+      parser.suggestKeywords(['DBPROPERTIES', 'LOCATION', 'MANAGEDLOCATION', 'OWNER']);
     }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' HdfsLocation_EDIT
    {
@@ -65,4 +69,8 @@ AlterDatabase_EDIT
    {
      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
    }
+ | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' ManagedLocation_EDIT
+   {
+     parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+   }
  ;

+ 28 - 7
desktop/core/src/desktop/js/parse/jison/sql/hive/create/create_database.jison

@@ -55,16 +55,19 @@ CreateDatabase_EDIT
  ;
 
 DatabaseDefinitionOptionals
- : OptionalComment OptionalHdfsLocation OptionalDbProperties
+ : OptionalComment OptionalHdfsLocation OptionalManagedLocation OptionalDbProperties
    {
      var keywords = [];
-     if (!$3) {
+     if (!$4) {
        keywords.push('WITH DBPROPERTIES');
      }
-     if (!$2 && !$3) {
+     if (!$3 && !$4) {
+       keywords.push('MANAGEDLOCATION');
+     }
+     if (!$2 && !$3 && !$4) {
        keywords.push('LOCATION');
      }
-     if (!$1 && !$2 && !$3) {
+     if (!$1 && !$2 && !$3 && !$4) {
        keywords.push('COMMENT');
      }
      if (keywords.length > 0) {
@@ -74,8 +77,10 @@ DatabaseDefinitionOptionals
  ;
 
 DatabaseDefinitionOptionals_EDIT
- : Comment_INVALID OptionalHdfsLocation OptionalDbProperties
- | OptionalComment HdfsLocation_EDIT OptionalDbProperties
+ : Comment_INVALID OptionalHdfsLocation OptionalManagedLocation OptionalDbProperties
+ | OptionalComment HdfsLocation_EDIT OptionalManagedLocation OptionalDbProperties
+ | OptionalComment OptionalHdfsLocation ManagedLocation_EDIT OptionalDbProperties
+ | OptionalComment OptionalHdfsLocation OptionalManagedLocation DbProperties_EDIT
  ;
 
 Comment_INVALID
@@ -85,6 +90,19 @@ Comment_INVALID
  | 'COMMENT' DOUBLE_QUOTE VALUE
  ;
 
+OptionalManagedLocation
+ :
+ | ManagedLocation
+ ;
+
+ManagedLocation
+ : 'MANAGEDLOCATION' HdfsPath
+ ;
+
+ManagedLocation_EDIT
+ : 'MANAGEDLOCATION' HdfsPath_EDIT
+ ;
+
 OptionalDbProperties
  :
  | DbProperties
@@ -93,7 +111,10 @@ OptionalDbProperties
 DbProperties
  : 'WITH' 'DBPROPERTIES' ParenthesizedPropertyAssignmentList
  | 'WITH' 'DBPROPERTIES'
- | 'WITH' 'CURSOR'
+ ;
+
+DbProperties_EDIT
+ : 'WITH' 'CURSOR'
    {
      parser.suggestKeywords(['DBPROPERTIES']);
    }

+ 1 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/sql.jisonlex

@@ -216,6 +216,7 @@ DOUBLE\s+PRECISION                   { return 'DOUBLE_PRECISION'; }
 'LOCATION'                           { this.begin('hdfs'); return 'LOCATION'; }
 'LOCK'                               { return 'LOCK'; }
 'LOCKS'                              { return 'LOCKS'; }
+'MANAGEDLOCATION'                    { this.begin('hdfs'); return 'MANAGEDLOCATION'; }
 'MATCHED'                            { return 'MATCHED'; }
 'MATERIALIZED'                       { return 'MATERIALIZED'; }
 'MERGE'                              { return 'MERGE'; }

+ 1 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_main.jison

@@ -157,6 +157,7 @@ NonReservedKeyword
  | 'LOCKS'
  | 'MATCHED'
  | 'MATERIALIZED'
+ | 'MANAGEDLOCATION'
  | 'MERGE'
  | 'METADATA'
  | 'MINUTE'

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


+ 25 - 2
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Alter.test.js

@@ -72,6 +72,18 @@ describe('hiveAutocompleteParser.js ALTER statements', () => {
       });
     });
 
+    it('should handle "ALTER DATABASE baa SET MANAGEDLOCATION \'/baa/boo\';|"', () => {
+      assertAutoComplete({
+        beforeCursor: "ALTER DATABASE baa SET MANAGEDLOCATION '/baa/boo';",
+        afterCursor: '',
+        noErrors: true,
+        containsKeywords: ['SELECT'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
+
     it('should suggest keywords for "ALTER |"', () => {
       assertAutoComplete({
         beforeCursor: 'ALTER ',
@@ -111,7 +123,7 @@ describe('hiveAutocompleteParser.js ALTER statements', () => {
         afterCursor: '',
         expectedResult: {
           lowerCase: false,
-          suggestKeywords: ['SET DBPROPERTIES', 'SET LOCATION', 'SET OWNER']
+          suggestKeywords: ['SET DBPROPERTIES', 'SET LOCATION', 'SET MANAGEDLOCATION', 'SET OWNER']
         }
       });
     });
@@ -122,7 +134,7 @@ describe('hiveAutocompleteParser.js ALTER statements', () => {
         afterCursor: '',
         expectedResult: {
           lowerCase: false,
-          suggestKeywords: ['DBPROPERTIES', 'LOCATION', 'OWNER']
+          suggestKeywords: ['DBPROPERTIES', 'LOCATION', 'MANAGEDLOCATION', 'OWNER']
         }
       });
     });
@@ -148,6 +160,17 @@ describe('hiveAutocompleteParser.js ALTER statements', () => {
         }
       });
     });
+
+    it('should suggest hdfs for "ALTER DATABASE boo SET MANAGEDLOCATION \'/|"', () => {
+      assertAutoComplete({
+        beforeCursor: "ALTER DATABASE boo SET MANAGEDLOCATION '/",
+        afterCursor: '',
+        expectedResult: {
+          lowerCase: false,
+          suggestHdfs: { path: '/' }
+        }
+      });
+    });
   });
 
   describe('ALTER INDEX', () => {

+ 13 - 2
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Create.test.js

@@ -135,7 +135,7 @@ describe('hiveAutocompleteParser.js CREATE statements', () => {
         afterCursor: '',
         expectedResult: {
           lowerCase: false,
-          suggestKeywords: ['COMMENT', 'LOCATION', 'WITH DBPROPERTIES']
+          suggestKeywords: ['COMMENT', 'LOCATION', 'MANAGEDLOCATION', 'WITH DBPROPERTIES']
         }
       });
     });
@@ -146,7 +146,7 @@ describe('hiveAutocompleteParser.js CREATE statements', () => {
         afterCursor: '',
         expectedResult: {
           lowerCase: false,
-          suggestKeywords: ['LOCATION', 'WITH DBPROPERTIES']
+          suggestKeywords: ['LOCATION', 'MANAGEDLOCATION', 'WITH DBPROPERTIES']
         }
       });
     });
@@ -155,6 +155,17 @@ describe('hiveAutocompleteParser.js CREATE statements', () => {
       assertAutoComplete({
         beforeCursor: "CREATE DATABASE foo COMMENT 'bla' LOCATION '/bla' ",
         afterCursor: '',
+        containsKeywords: ['WITH DBPROPERTIES'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
+
+    it("should suggest keywords for \"CREATE DATABASE foo COMMENT 'bla' MANAGEDLOCATION '/bla' |\"", () => {
+      assertAutoComplete({
+        beforeCursor: "CREATE DATABASE foo COMMENT 'bla' MANAGEDLOCATION '/bla' ",
+        afterCursor: '',
         expectedResult: {
           lowerCase: false,
           suggestKeywords: ['WITH DBPROPERTIES']

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels