Browse Source

HUE-6835 [autocomplete] Improve ALTER TABLE autocomplete for Impala

Johan Ahlen 8 years ago
parent
commit
7635a36489

+ 16 - 7
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_alter.jison

@@ -80,7 +80,7 @@ AlterIndex_EDIT
  ;
 
 AlterTable
- : AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs
+ : AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs OptionalCachedInOrUncached
  | AlterTableLeftSide AnyAdd OptionalIfNotExists '<impala>RANGE' 'PARTITION' RangePartitionSpec
  | AlterTableLeftSide AnyAdd OptionalIfNotExists '<impala>RANGE' '<impala>PARTITION_VALUE' '=' UnsignedValueSpecification
  | AlterTableLeftSide AnyRename 'TO' RegularOrBackTickedSchemaQualifiedName
@@ -93,7 +93,7 @@ AlterTable
 
 AlterTable_EDIT
  : AlterTableLeftSide_EDIT
- | AlterTableLeftSide_EDIT AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs
+ | AlterTableLeftSide_EDIT AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs OptionalCachedInOrUncached
  | AlterTableLeftSide_EDIT AnyRename 'TO' RegularOrBackTickedSchemaQualifiedName
  | AlterTableLeftSide_EDIT HiveSpecificOperations
  | AlterTableLeftSide_EDIT DropOperations
@@ -116,12 +116,13 @@ AlterTable_EDIT
      parser.suggestKeywords(['COLUMNS']);
    }
  | AlterTableLeftSide AnyAdd OptionalIfNotExists_EDIT
- | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec HdfsLocation_EDIT OptionalPartitionSpecs
- | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs_EDIT
- | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs 'CURSOR'
+ | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec HdfsLocation_EDIT OptionalPartitionSpecs OptionalCachedInOrUncached
+ | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs_EDIT OptionalCachedInOrUncached
+ | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs CachedIn_EDIT
+ | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec OptionalHdfsLocation OptionalPartitionSpecs OptionalCachedInOrUncached 'CURSOR'
    {
      if (parser.isHive()) {
-       if (!$5 && !$6) {
+       if (!$5 && !$6 && !$7) {
          parser.suggestKeywords(['LOCATION', 'PARTITION']);
        } else if ($6 && $6.suggestKeywords) {
          var keywords = parser.createWeightedKeywords($6.suggestKeywords, 2);
@@ -130,9 +131,17 @@ AlterTable_EDIT
        } else {
          parser.suggestKeywords(['PARTITION']);
        }
+     } else if (parser.isImpala()) {
+       if (!$5 && !$6 && !$7) {
+         parser.suggestKeywords(['LOCATION', 'CACHED IN', 'UNCACHED']);
+       } else if (!$7) {
+         parser.suggestKeywords(['CACHED IN', 'UNCACHED']);
+       } else if ($7 && $7.suggestKeywords) {
+         parser.suggestKeywords($7.suggestKeywords);
+       }
      }
    }
- | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec_EDIT OptionalHdfsLocation OptionalPartitionSpecs
+ | AlterTableLeftSide AnyAdd OptionalIfNotExists PartitionSpec_EDIT OptionalHdfsLocation OptionalPartitionSpecs OptionalCachedIn
  | AlterTableLeftSide AnyAdd OptionalIfNotExists '<impala>RANGE' 'CURSOR'
    {
      parser.suggestKeywords(['PARTITION']);

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

@@ -124,19 +124,6 @@ OptionalComment_INVALID
  : Comment_INVALID
  ;
 
-OptionalHdfsLocation
- :
- | HdfsLocation
- ;
-
-HdfsLocation
- : HiveOrImpalaLocation HdfsPath
- ;
-
-HdfsLocation_EDIT
- : HiveOrImpalaLocation HdfsPath_EDIT
- ;
-
 OptionalHiveDbProperties
  :
  | HiveDbProperties
@@ -1168,47 +1155,6 @@ CommitLocations
    }
  ;
 
-OptionalCachedIn
- :
- | CachedIn OptionalWithReplication
-   {
-     if (!$2) {
-       $$ = { suggestKeywords: ['WITH REPLICATION ='] };
-     }
-   }
- ;
-
-CachedIn
- : '<impala>CACHED' 'IN' QuotedValue
- ;
-
-CachedIn_EDIT
- : '<impala>CACHED' 'CURSOR'
-   {
-     parser.suggestKeywords(['IN']);
-   }
- ;
-
-OptionalWithReplication
- :
- | WithReplication
- ;
-
-WithReplication
- : 'WITH' '<impala>REPLICATION' '=' SignedInteger
- ;
-
-WithReplication_EDIT
- : 'WITH' 'CURSOR'
-   {
-     parser.suggestKeywords(['REPLICATION =']);
-   }
- | 'WITH' '<impala>REPLICATION' 'CURSOR'
-   {
-     parser.suggestKeywords(['=']);
-   }
- ;
-
 ViewDefinition
  : AnyCreate AnyView OptionalIfNotExists SchemaQualifiedIdentifier OptionalParenthesizedViewColumnList OptionalComment OptionalHiveTblproperties AnyAs QuerySpecification
  ;

+ 66 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison

@@ -675,7 +675,6 @@ RangePartitionComparisonOperator
  | '>'
  ;
 
-
 ConfigurationName
  : RegularIdentifier
  | 'CURSOR'
@@ -886,6 +885,72 @@ PartitionExpression_EDIT
    }
  ;
 
+OptionalHdfsLocation
+ :
+ | HdfsLocation
+ ;
+
+HdfsLocation
+ : HiveOrImpalaLocation HdfsPath
+ ;
+
+HdfsLocation_EDIT
+ : HiveOrImpalaLocation HdfsPath_EDIT
+ ;
+
+OptionalCachedInOrUncached
+ :
+ | CachedIn OptionalWithReplication
+   {
+     if (!$2) {
+       $$ = { suggestKeywords: ['WITH REPLICATION ='] };
+     }
+   }
+ | '<impala>UNCACHED'
+ ;
+
+
+OptionalCachedIn
+ :
+ | CachedIn OptionalWithReplication
+   {
+     if (!$2) {
+       $$ = { suggestKeywords: ['WITH REPLICATION ='] };
+     }
+   }
+ ;
+
+CachedIn
+ : '<impala>CACHED' 'IN' QuotedValue
+ ;
+
+CachedIn_EDIT
+ : '<impala>CACHED' 'CURSOR'
+   {
+     parser.suggestKeywords(['IN']);
+   }
+ ;
+
+OptionalWithReplication
+ :
+ | WithReplication
+ ;
+
+WithReplication
+ : 'WITH' '<impala>REPLICATION' '=' SignedInteger
+ ;
+
+WithReplication_EDIT
+ : 'WITH' 'CURSOR'
+   {
+     parser.suggestKeywords(['REPLICATION =']);
+   }
+ | 'WITH' '<impala>REPLICATION' 'CURSOR'
+   {
+     parser.suggestKeywords(['=']);
+   }
+ ;
+
 RegularOrBacktickedIdentifier
  : RegularIdentifier
  | 'BACKTICK' 'VALUE' 'BACKTICK'  -> $2

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

@@ -1523,6 +1523,68 @@
           });
         });
 
+        it('should handle "ALTER TABLE bar ADD PARTITION (a=1) LOCATION \'/bla\' UNCACHED; |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'ALTER TABLE bar ADD PARTITION (a=1) LOCATION \'/bla\' UNCACHED; ',
+            afterCursor: '',
+            noErrors: true,
+            containsKeywords: ['SELECT'],
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should handle "ALTER TABLE bar ADD IF NOT EXISTS PARTITION (a=1) LOCATION \'/bla\' CACHED IN \'boo\' WITH REPLICATION = 2; |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'ALTER TABLE bar ADD IF NOT EXISTS PARTITION (a=1) LOCATION \'/bla\' CACHED IN \'boo\' WITH REPLICATION = 2; ',
+            afterCursor: '',
+            noErrors: true,
+            containsKeywords: ['SELECT'],
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "ALTER TABLE bar ADD PARTITION (a=1) |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'ALTER TABLE bar ADD PARTITION (a=1) ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['CACHED IN', 'LOCATION', 'UNCACHED']
+            }
+          });
+        });
+
+        it('should suggest keywords for "ALTER TABLE bar ADD PARTITION (a=1) CACHED |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'ALTER TABLE bar ADD PARTITION (a=1) CACHED ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['IN']
+            }
+          });
+        });
+
+        it('should suggest keywords for "ALTER TABLE bar ADD PARTITION (a=1) CACHED IN \'boo\' |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'ALTER TABLE bar ADD PARTITION (a=1) CACHED IN \'boo\' ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestKeywords: ['WITH REPLICATION =']
+            }
+          });
+        });
+
         it('should suggest columns for "ALTER TABLE bar CHANGE |"', function() {
           assertAutoComplete({
             beforeCursor: 'ALTER TABLE bar CHANGE ',

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