Ver Fonte

HUE-6958 [autocomplete] Add autocomplete support for Hive SHOW VIEWS statements

Johan Ahlen há 8 anos atrás
pai
commit
7b86ddcf8d

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

@@ -66,6 +66,7 @@
 <hive>'TIMESTAMP'                          { return '<hive>TIMESTAMP'; }
 <hive>'USER'                               { return '<hive>USER'; }
 <hive>'USING'                              { return '<hive>USING'; }
+<hive>'VIEWS'                              { return '<hive>VIEWS'; }
 
 // Non-reserved Keywords
 <hive>'ADD'                                { return '<hive>ADD'; }

+ 19 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_alter.jison

@@ -50,35 +50,53 @@ AlterStatement_EDIT
 
 AlterDatabase
  : 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>DBPROPERTIES' ParenthesizedPropertyAssignmentList
+    {
+      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+    }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' HdfsLocation
+    {
+      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+    }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>OWNER' PrincipalSpecification
+    {
+      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+    }
  ;
 
 AlterDatabase_EDIT
  : 'ALTER' DatabaseOrSchema 'CURSOR'
    {
      if (parser.isHive()) {
-      parser.suggestDatabases();
+       parser.suggestDatabases();
      }
    }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'CURSOR'
    {
+     parser.addDatabaseLocation(@3, [ { name: $3 } ]);
      if (parser.isHive()) {
        parser.suggestKeywords(['SET DBPROPERTIES', 'SET LOCATION', 'SET OWNER']);
      }
    }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' 'CURSOR'
     {
+      parser.addDatabaseLocation(@3, [ { name: $3 } ]);
       if (parser.isHive()) {
         parser.suggestKeywords(['DBPROPERTIES', 'LOCATION', 'OWNER']);
       }
     }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' HdfsLocation_EDIT
+   {
+     parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+   }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>OWNER' 'CURSOR'
    {
+     parser.addDatabaseLocation(@3, [ { name: $3 } ]);
      parser.suggestKeywords(['GROUP', 'ROLE', 'USER']);
    }
  | 'ALTER' DatabaseOrSchema RegularOrBacktickedIdentifier 'SET' '<hive>OWNER' PrincipalSpecification_EDIT
+   {
+     parser.addDatabaseLocation(@3, [ { name: $3 } ]);
+   }
  ;
 
 AlterIndex

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison


+ 52 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_show.jison

@@ -42,6 +42,7 @@ ShowStatement
  | ShowTablesStatement
  | ShowTblPropertiesStatement
  | ShowTransactionsStatement
+ | ShowViewsStatement
  ;
 
 AnyShow
@@ -53,7 +54,7 @@ ShowStatement_EDIT
  : AnyShow 'CURSOR'
    {
      if (parser.isHive()) {
-       parser.suggestKeywords(['COLUMNS', 'COMPACTIONS', 'CONF', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FORMATTED', 'FUNCTIONS', 'GRANT', 'INDEX', 'INDEXES', 'LOCKS', 'PARTITIONS', 'PRINCIPALS', 'ROLE GRANT', 'ROLES', 'SCHEMAS', 'TABLE EXTENDED', 'TABLES', 'TBLPROPERTIES', 'TRANSACTIONS']);
+       parser.suggestKeywords(['COLUMNS', 'COMPACTIONS', 'CONF', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FORMATTED', 'FUNCTIONS', 'GRANT', 'INDEX', 'INDEXES', 'LOCKS', 'PARTITIONS', 'PRINCIPALS', 'ROLE GRANT', 'ROLES', 'SCHEMAS', 'TABLE EXTENDED', 'TABLES', 'TBLPROPERTIES', 'TRANSACTIONS', 'VIEWS']);
      } else if (parser.isImpala()) {
        parser.suggestKeywords(['AGGREGATE FUNCTIONS', 'ANALYTIC FUNCTIONS', 'COLUMN STATS', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FILES IN', 'FUNCTIONS', 'GRANT ROLE', 'PARTITIONS', 'RANGE PARTITIONS', 'ROLE GRANT GROUP', 'ROLES', 'SCHEMAS', 'TABLE STATS', 'TABLES']);
      } else {
@@ -96,6 +97,7 @@ ShowStatement_EDIT
  | ShowTableStatement_EDIT
  | ShowTablesStatement_EDIT
  | ShowTblPropertiesStatement_EDIT
+ | ShowViewsStatement_EDIT
  ;
 
 ShowColumnStatsStatement
@@ -626,4 +628,53 @@ ShowTblPropertiesStatement_EDIT
 
 ShowTransactionsStatement
  : AnyShow '<hive>TRANSACTIONS'
+ ;
+
+ShowViewsStatement
+ : AnyShow '<hive>VIEWS' OptionalInOrFromDatabase OptionalLike
+ ;
+
+ShowViewsStatement_EDIT
+ : AnyShow '<hive>VIEWS' OptionalInOrFromDatabase OptionalLike 'CURSOR'
+   {
+     if (!$4 && !$3) {
+       parser.suggestKeywords([{ value: 'IN', weight: 2 }, { value: 'FROM', weight: 2 }, { value: 'LIKE', weight: 1 }]);
+     } else if (!$4) {
+       parser.suggestKeywords(['LIKE']);
+     }
+   }
+ | AnyShow '<hive>VIEWS' InOrFromDatabase_EDIT OptionalLike
+ | AnyShow '<hive>VIEWS' OptionalInOrFromDatabase Like_EDIT
+ ;
+
+OptionalInOrFromDatabase
+ :
+ | 'IN' RegularOrBacktickedIdentifier
+   {
+     parser.addDatabaseLocation(@2, [ { name: $2 } ]);
+   }
+ | 'FROM' RegularOrBacktickedIdentifier
+   {
+     parser.addDatabaseLocation(@2, [ { name: $2 } ]);
+   }
+ ;
+
+InOrFromDatabase_EDIT
+ : 'IN' 'CURSOR'
+   {
+     parser.suggestDatabases();
+   }
+ | 'FROM' 'CURSOR'
+   {
+     parser.suggestDatabases();
+   }
+ ;
+
+OptionalLike
+ :
+ | 'LIKE' SingleQuotedValue
+ ;
+
+Like_EDIT
+ : 'LIKE' 'CURSOR'
  ;

+ 76 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecShow.js

@@ -58,7 +58,7 @@
           dialect: 'hive',
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['COLUMNS', 'COMPACTIONS', 'CONF', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FORMATTED', 'FUNCTIONS', 'GRANT', 'INDEX', 'INDEXES', 'LOCKS', 'PARTITIONS', 'PRINCIPALS', 'ROLE GRANT', 'ROLES', 'SCHEMAS', 'TABLE EXTENDED', 'TABLES', 'TBLPROPERTIES', 'TRANSACTIONS']
+            suggestKeywords: ['COLUMNS', 'COMPACTIONS', 'CONF', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FORMATTED', 'FUNCTIONS', 'GRANT', 'INDEX', 'INDEXES', 'LOCKS', 'PARTITIONS', 'PRINCIPALS', 'ROLE GRANT', 'ROLES', 'SCHEMAS', 'TABLE EXTENDED', 'TABLES', 'TBLPROPERTIES', 'TRANSACTIONS', 'VIEWS']
           }
         });
       });
@@ -1080,6 +1080,20 @@
         assertAutoComplete({
           beforeCursor: 'SHOW TRANSACTIONS;',
           afterCursor: '',
+          noErrors: true,
+          dialect: 'hive',
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "SHOW VIEWS;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW VIEWS;',
+          afterCursor: '',
+          noErrors: true,
           dialect: 'hive',
           containsKeywords: ['SELECT'],
           expectedResult: {
@@ -1087,6 +1101,67 @@
           }
         });
       });
+
+      it('should handle "SHOW VIEWS IN boo LIKE \'asdf\';|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW VIEWS IN boo LIKE \'asdf\';',
+          afterCursor: '',
+          noErrors: true,
+          dialect: 'hive',
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest keywords for "SHOW VIEWS |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW VIEWS ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['FROM', 'IN', 'LIKE']
+          }
+        });
+      });
+
+      it('should suggest databases for "SHOW VIEWS IN |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW VIEWS IN ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestDatabases: { }
+          }
+        });
+      });
+
+      it('should suggest databases for "SHOW VIEWS FROM |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW VIEWS FROM ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestDatabases: { }
+          }
+        });
+      });
+
+      it('should suggest keywords for "SHOW VIEWS IN boo |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW VIEWS IN boo ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['LIKE']
+          }
+        });
+      });
     });
 
     describe('impala specific', function () {

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff