Ver código fonte

HUE-9464 [editor] Update TRUNCATE syntax for the Hive parser

Johan Ahlen 5 anos atrás
pai
commit
a12a075ae9

+ 1 - 1
desktop/core/src/desktop/js/parse/jison/sql/hive/alter/alter_index.jison

@@ -40,7 +40,7 @@ AlterIndex_EDIT
      parser.suggestDatabases({ appendDot: true });
    }
  | 'ALTER' 'INDEX' RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier_EDIT
- | 'ALTER' 'INDEX' RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | 'ALTER' 'INDEX' RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
    {
      parser.addTablePrimary($5);
    }

+ 1 - 1
desktop/core/src/desktop/js/parse/jison/sql/hive/alter/alter_table.jison

@@ -161,7 +161,7 @@ AlterTable_EDIT
    {
      parser.suggestKeywords(['PARTITION']);
    }
- | AlterTableLeftSide 'TOUCH' OptionalPartitionSpec_EDIT
+ | AlterTableLeftSide 'TOUCH' PartitionSpec_EDIT
  | AlterTableLeftSide PartitionOperations_EDIT
  | AlterTableLeftSide DropOperations_EDIT
  | AlterTableLeftSide 'CURSOR'

+ 2 - 2
desktop/core/src/desktop/js/parse/jison/sql/hive/analyze/analyze_table.jison

@@ -45,7 +45,7 @@ AnalyzeTableStatement_EDIT
        parser.yy.result.suggestTables.onlyTables = true;
      }
    }
- | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT
    {
      parser.addTablePrimary($3);
    }
@@ -89,7 +89,7 @@ AnalyzeTableStatement_EDIT
      parser.addTablePrimary($3);
    }
  | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec 'COMPUTE' 'STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
- | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT 'COMPUTE' 'STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
+ | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT 'COMPUTE' 'STATISTICS' OptionalForColumns OptionalCacheMetadata OptionalNoscan
  | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'COMPUTE' 'STATISTICS' ForColumns_EDIT OptionalCacheMetadata OptionalNoscan
  | 'ANALYZE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'COMPUTE' 'STATISTICS' OptionalForColumns CacheMetadata_EDIT OptionalNoscan
  ;

+ 2 - 2
desktop/core/src/desktop/js/parse/jison/sql/hive/describe/describe.jison

@@ -66,8 +66,8 @@ DescribeStatement_EDIT
        parser.suggestKeywords(['PARTITION']);
      }
    }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec_EDIT
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain PartitionSpec_EDIT
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier PartitionSpec_EDIT
 
  | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR'
    {

+ 2 - 2
desktop/core/src/desktop/js/parse/jison/sql/hive/insert/insert.jison

@@ -147,7 +147,7 @@ InsertWithoutQuery_EDIT
    {
      $$ = { keepTables: true }
    }
- | 'INSERT' 'OVERWRITE' OptionalTable SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT OptionalIfNotExists
+ | 'INSERT' 'OVERWRITE' OptionalTable SchemaQualifiedTableIdentifier PartitionSpec_EDIT OptionalIfNotExists
    {
      $4.owner = 'insert';
      parser.addTablePrimary($4);
@@ -183,7 +183,7 @@ InsertWithoutQuery_EDIT
    {
      $$ = { keepTables: true }
    }
- | 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT OptionalParenthesizedColumnList
+ | 'INSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier PartitionSpec_EDIT OptionalParenthesizedColumnList
    {
      $4.owner = 'insert';
      parser.addTablePrimary($4);

+ 1 - 1
desktop/core/src/desktop/js/parse/jison/sql/hive/load/load_data.jison

@@ -70,7 +70,7 @@ LoadDataStatement_EDIT
        parser.suggestKeywords(['INPUTFORMAT']);
      }
    }
- | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT OptionalInputFormat
+ | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier PartitionSpec_EDIT OptionalInputFormat
    {
      parser.addTablePrimary($9);
    }

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

@@ -670,10 +670,6 @@ OptionalPartitionSpec
  | PartitionSpec
  ;
 
-OptionalPartitionSpec_EDIT
- : PartitionSpec_EDIT
- ;
-
 PartitionSpec
  : 'PARTITION' '(' PartitionSpecList ')'
  ;

+ 12 - 10
desktop/core/src/desktop/js/parse/jison/sql/hive/truncate/truncate_table.jison

@@ -23,36 +23,38 @@ DataDefinition_EDIT
  ;
 
 TruncateTableStatement
- : 'TRUNCATE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+ : 'TRUNCATE' OptionalTable SchemaQualifiedTableIdentifier OptionalPartitionSpec
    {
      parser.addTablePrimary($3);
    }
  ;
 
 TruncateTableStatement_EDIT
- : 'TRUNCATE' 'CURSOR'
-   {
-     parser.suggestKeywords(['TABLE']);
-   }
- | 'TRUNCATE' 'TABLE' 'CURSOR' OptionalPartitionSpec
+ : 'TRUNCATE' OptionalTable 'CURSOR' OptionalPartitionSpec
    {
+     if (!$2) {
+       parser.suggestKeywords(['TABLE']);
+     }
      parser.suggestTables();
      parser.suggestDatabases({ appendDot: true });
    }
- | 'TRUNCATE' 'TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
- | 'TRUNCATE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
+ | 'TRUNCATE' OptionalTable SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
+ | 'TRUNCATE' OptionalTable SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
    {
      parser.addTablePrimary($3);
      if (!$4) {
        parser.suggestKeywords(['PARTITION']);
      }
    }
- | 'TRUNCATE' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | 'TRUNCATE' OptionalTable SchemaQualifiedTableIdentifier PartitionSpec_EDIT
    {
      parser.addTablePrimary($3);
    }
- | 'TRUNCATE' 'TABLE' 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+ | 'TRUNCATE' OptionalTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
    {
+     if (!$2) {
+       parser.suggestKeywords(['TABLE']);
+     }
      parser.addTablePrimary($4);
    }
  ;

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


+ 58 - 0
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Abort.test.js

@@ -0,0 +1,58 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import hiveAutocompleteParser from '../hiveAutocompleteParser';
+describe('hiveAutocompleteParser.js DROP statements', () => {
+  beforeAll(() => {
+    hiveAutocompleteParser.yy.parseError = function (msg) {
+      throw Error(msg);
+    };
+  });
+
+  const assertAutoComplete = testDefinition => {
+    const debug = false;
+
+    expect(
+      hiveAutocompleteParser.parseSql(
+        testDefinition.beforeCursor,
+        testDefinition.afterCursor,
+        debug
+      )
+    ).toEqualDefinition(testDefinition);
+  };
+
+  it('should suggest keywords for "|"', () => {
+    assertAutoComplete({
+      beforeCursor: '',
+      afterCursor: '',
+      containsKeywords: ['ABORT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "ABORT |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'ABORT ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['TRANSACTIONS']
+      }
+    });
+  });
+});

+ 0 - 70
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Drop.test.js

@@ -34,28 +34,6 @@ describe('hiveAutocompleteParser.js DROP statements', () => {
     ).toEqualDefinition(testDefinition);
   };
 
-  it('should suggest keywords for "|"', () => {
-    assertAutoComplete({
-      beforeCursor: '',
-      afterCursor: '',
-      containsKeywords: ['ABORT'],
-      expectedResult: {
-        lowerCase: false
-      }
-    });
-  });
-
-  it('should suggest keywords for "ABORT |"', () => {
-    assertAutoComplete({
-      beforeCursor: 'ABORT ',
-      afterCursor: '',
-      expectedResult: {
-        lowerCase: false,
-        suggestKeywords: ['TRANSACTIONS']
-      }
-    });
-  });
-
   it('should suggest keywords for "DROP |"', () => {
     assertAutoComplete({
       beforeCursor: 'DROP ',
@@ -628,52 +606,4 @@ describe('hiveAutocompleteParser.js DROP statements', () => {
       });
     });
   });
-
-  describe('TRUNCATE TABLE', () => {
-    it('should handle "TRUNCATE TABLE boo PARTITION (baa=1, boo = \'baa\'); |"', () => {
-      assertAutoComplete({
-        beforeCursor: "TRUNCATE TABLE boo PARTITION (baa=1, boo = 'baa'); ",
-        afterCursor: '',
-        containsKeywords: ['SELECT'],
-        noErrors: true,
-        expectedResult: {
-          lowerCase: false
-        }
-      });
-    });
-
-    it('should suggest keywords for "TRUNCATE |"', () => {
-      assertAutoComplete({
-        beforeCursor: 'TRUNCATE ',
-        afterCursor: '',
-        expectedResult: {
-          lowerCase: false,
-          suggestKeywords: ['TABLE']
-        }
-      });
-    });
-
-    it('should suggest tables for "TRUNCATE TABLE |"', () => {
-      assertAutoComplete({
-        beforeCursor: 'TRUNCATE TABLE ',
-        afterCursor: '',
-        expectedResult: {
-          lowerCase: false,
-          suggestTables: {},
-          suggestDatabases: { appendDot: true }
-        }
-      });
-    });
-
-    it('should suggest keywords for "TRUNCATE TABLE boo |"', () => {
-      assertAutoComplete({
-        beforeCursor: 'TRUNCATE TABLE boo ',
-        afterCursor: '',
-        expectedResult: {
-          lowerCase: false,
-          suggestKeywords: ['PARTITION']
-        }
-      });
-    });
-  });
 });

+ 118 - 0
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Truncate.test.js

@@ -0,0 +1,118 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import hiveAutocompleteParser from '../hiveAutocompleteParser';
+describe('hiveAutocompleteParser.js DROP statements', () => {
+  beforeAll(() => {
+    hiveAutocompleteParser.yy.parseError = function (msg) {
+      throw Error(msg);
+    };
+  });
+
+  const assertAutoComplete = testDefinition => {
+    const debug = false;
+
+    expect(
+      hiveAutocompleteParser.parseSql(
+        testDefinition.beforeCursor,
+        testDefinition.afterCursor,
+        debug
+      )
+    ).toEqualDefinition(testDefinition);
+  };
+
+  it('should suggest keywords for "|"', () => {
+    assertAutoComplete({
+      beforeCursor: '',
+      afterCursor: '',
+      containsKeywords: ['TRUNCATE'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should handle "TRUNCATE TABLE boo PARTITION (baa=1, boo = \'baa\'); |"', () => {
+    assertAutoComplete({
+      beforeCursor: "TRUNCATE TABLE boo PARTITION (baa=1, boo = 'baa'); ",
+      afterCursor: '',
+      containsKeywords: ['SELECT'],
+      noErrors: true,
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should handle "TRUNCATE boo PARTITION (baa=1, boo = \'baa\'); |"', () => {
+    assertAutoComplete({
+      beforeCursor: "TRUNCATE boo PARTITION (baa=1, boo = 'baa'); ",
+      afterCursor: '',
+      containsKeywords: ['SELECT'],
+      noErrors: true,
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "TRUNCATE |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'TRUNCATE ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['TABLE'],
+        suggestTables: {},
+        suggestDatabases: { appendDot: true }
+      }
+    });
+  });
+
+  it('should suggest tables for "TRUNCATE TABLE |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'TRUNCATE TABLE ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestTables: {},
+        suggestDatabases: { appendDot: true }
+      }
+    });
+  });
+
+  it('should suggest keywords for "TRUNCATE TABLE boo |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'TRUNCATE TABLE boo ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['PARTITION']
+      }
+    });
+  });
+
+  it('should suggest keywords for "TRUNCATE boo |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'TRUNCATE boo ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['PARTITION']
+      }
+    });
+  });
+});

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js


Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff