Explorar o código

HUE-4769 [editor] The autocompleter should support INSERT OVERWRITE DIRECTORY

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

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

@@ -123,6 +123,7 @@
 <hive>'ORC'                                { return '<hive>ORC'; }
 <hive>'OUTPUTFORMAT'                       { return '<hive>OUTPUTFORMAT'; }
 <hive>'OVERWRITE'                          { return '<hive>OVERWRITE'; }
+<hive>OVERWRITE\s+DIRECTORY                { this.begin('hdfs'); return '<hive>OVERWRITE_DIRECTORY'; }
 <hive>'PARQUET'                            { return '<hive>PARQUET'; }
 <hive>'PARTITIONED'                        { return '<hive>PARTITIONED'; }
 <hive>'PARTITIONS'                         { return '<hive>PARTITIONS'; }

+ 14 - 3
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_insert.jison

@@ -123,7 +123,15 @@ HiveInsertWithoutQuery
        $$ = { suggestKeywords: ['STORED AS'] };
      }
    }
- | '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalParenthesizedColumnList
+ | '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs
+    {
+      if (!$4 && !$5) {
+        $$ = { suggestKeywords: [{ value: 'ROW FORMAT', weight: 2 }, { value: 'STORED AS', weight: 1}] };
+      } else if (!$5) {
+        $$ = { suggestKeywords: ['STORED AS'] };
+      }
+    }
+  | '<hive>INSERT' 'INTO' OptionalHiveTable SchemaQualifiedTableIdentifier OptionalPartitionSpec OptionalParenthesizedColumnList
    {
      $4.owner = 'insert';
      addTablePrimary($4);
@@ -143,7 +151,7 @@ HiveInsertWithoutQuery_EDIT
  | '<hive>INSERT' '<hive>OVERWRITE' OptionalHiveTable 'CURSOR'
    {
      if (!$3) {
-       suggestKeywords(['LOCAL DIRECTORY', 'TABLE']);
+       suggestKeywords(['DIRECTORY', 'LOCAL DIRECTORY', 'TABLE']);
      }
      suggestTables();
      suggestDatabases({ appendDot: true });
@@ -166,13 +174,16 @@ HiveInsertWithoutQuery_EDIT
      $4.owner = 'insert';
      addTablePrimary($4);
    }
- | '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL'
+ | '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' 'CURSOR'
    {
      suggestKeywords(['DIRECTORY']);
    }
  | '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath_EDIT OptionalInsertRowFormat OptionalStoredAs
  | '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath OptionalInsertRowFormat_EDIT OptionalStoredAs
  | '<hive>INSERT' '<hive>OVERWRITE' '<hive>LOCAL' '<hive>DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs_EDIT
+ | '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath_EDIT OptionalInsertRowFormat OptionalStoredAs  // DIRECTORY is a non-reserved keyword
+ | '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat_EDIT OptionalStoredAs
+ | '<hive>INSERT' '<hive>OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs_EDIT
  | '<hive>INSERT' 'INTO' OptionalHiveTable 'CURSOR'
    {
      if (!$3) {

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


+ 68 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecInsert.js

@@ -160,6 +160,20 @@ define([
         });
       });
 
+      it('should handle "INSERT OVERWRITE DIRECTORY \'blabla\' SELECT * FROM boo;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INSERT OVERWRITE DIRECTORY \'blabla\' SELECT * FROM boo;',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          hasLocations: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
       it('should handle "INSERT INTO bla.boo SELECT ba.boo, ba, ble FROM db.tbl; |"', function() {
         assertAutoComplete({
           beforeCursor: 'INSERT INTO bla.boo SELECT ba.boo, ba, ble FROM db.tbl;',
@@ -741,6 +755,60 @@ define([
         });
       });
 
+      it('should suggest tables for "INSERT OVERWRITE |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INSERT OVERWRITE ',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestTables: {},
+            suggestDatabases: { appendDot: true },
+            suggestKeywords: ['DIRECTORY', 'LOCAL DIRECTORY', 'TABLE' ]
+          }
+        });
+      });
+
+      it('should suggest tables for "INSERT OVERWRITE LOCAL |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INSERT OVERWRITE LOCAL ',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['DIRECTORY' ]
+          }
+        });
+      });
+
+      it('should suggest hdfs for "INSERT OVERWRITE DIRECTORY \'|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INSERT OVERWRITE DIRECTORY \'',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestHdfs: { path: '' }
+          }
+        });
+      });
+
+      it('should suggest keywords for "INSERT OVERWRITE DIRECTORY \'blabla\' |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'INSERT OVERWRITE DIRECTORY \'blabla\' ',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['SELECT']
+          }
+        });
+      });
+
       it('should suggest keywords for "INSERT OVERWRITE bla.ble |"', function() {
         assertAutoComplete({
           beforeCursor: 'INSERT OVERWRITE bla.ble ',

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