Explorar o código

HUE-9099 [frontend] Extend the Hive LOAD statement syntax in the parser

Johan Ahlen %!s(int64=6) %!d(string=hai) anos
pai
achega
fd11736eef

+ 29 - 7
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_load.jison

@@ -27,7 +27,7 @@ DataManipulation_EDIT
  ;
 
 LoadStatement
- : 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+ : 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalInputFormat
    {
      parser.addTablePrimary($9);
    }
@@ -64,19 +64,25 @@ LoadStatement_EDIT
      parser.suggestTables();
      parser.suggestDatabases({ appendDot: true });
    }
- | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
- | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR'
+ | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec OptionalInputFormat
+ | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalInputFormat 'CURSOR'
    {
      parser.addTablePrimary($9);
-     if (!$10) {
-       parser.suggestKeywords(['PARTITION']);
+     if (!$10 && !$11) {
+       parser.suggestKeywords(['INPUTFORMAT', 'PARTITION']);
+     } else if ($10 && !$11) {
+       parser.suggestKeywords(['INPUTFORMAT']);
      }
    }
- | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+ | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT OptionalInputFormat
+   {
+     parser.addTablePrimary($9);
+   }
+ | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec InputFormat_EDIT
    {
      parser.addTablePrimary($9);
    }
- | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath_EDIT OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+ | 'LOAD' 'DATA' OptionalLocal 'INPATH' HdfsPath_EDIT OptionalOverwrite 'INTO' 'TABLE' SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalInputFormat
    {
      parser.addTablePrimary($9);
    }
@@ -92,6 +98,22 @@ OptionalLocal
  | 'LOCAL'
  ;
 
+OptionalInputFormat
+ :
+ | InputFormat
+ ;
+
+InputFormat
+ : 'INPUTFORMAT' QuotedValue 'SERDE' QuotedValue
+ ;
+
+InputFormat_EDIT
+ : 'INPUTFORMAT' QuotedValue 'CURSOR'
+   {
+     parser.suggestKeywords(['SERDE']);
+   }
+ ;
+
 ImportStatement
  : 'IMPORT' OptionalTableWithPartition PushHdfsLexerState 'FROM' HdfsPath OptionalHdfsLocation
  ;

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


+ 29 - 1
desktop/core/src/desktop/js/parse/sql/hive/test/hiveAutocompleteParser.Load.test.js

@@ -47,6 +47,23 @@ describe('hiveAutocompleteParser.js LOAD statements', () => {
     });
   });
 
+  it(
+    "should handle \"LOAD DATA LOCAL INPATH '/filepath' OVERWRITE INTO TABLE db.tablename PARTITION (partcol1='baa', partcol2=1) " +
+      "INPUTFORMAT 'foo' SERDE 'bar';|\"",
+    () => {
+      assertAutoComplete({
+        beforeCursor:
+          "LOAD DATA LOCAL INPATH '/filepath' OVERWRITE INTO TABLE db.tablename PARTITION (partcol1='baa', partcol2=1) INPUTFORMAT 'foo' SERDE 'bar';",
+        afterCursor: '',
+        noErrors: true,
+        containsKeywords: ['SELECT'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    }
+  );
+
   it('should suggest keywords for "|"', () => {
     assertAutoComplete({
       beforeCursor: '',
@@ -164,7 +181,7 @@ describe('hiveAutocompleteParser.js LOAD statements', () => {
       afterCursor: '',
       expectedResult: {
         lowerCase: false,
-        suggestKeywords: ['PARTITION']
+        suggestKeywords: ['INPUTFORMAT', 'PARTITION']
       }
     });
   });
@@ -179,4 +196,15 @@ describe('hiveAutocompleteParser.js LOAD statements', () => {
       }
     });
   });
+
+  it("should suggest keywords for \"LOAD DATA INPATH 'baa' INTO TABLE baa INPUTORMAT 'foo' |\"", () => {
+    assertAutoComplete({
+      beforeCursor: "LOAD DATA INPATH 'baa' INTO TABLE baa INPUTFORMAT '\foo' ",
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['SERDE']
+      }
+    });
+  });
 });

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio