Explorar o código

HUE-4581 [editor] The new autocompleter should support DROP FUNCTION

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

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

@@ -135,7 +135,7 @@
 <hive>'SORTED'                             { return '<hive>SORTED'; }
 <hive>'STATISTICS'                         { return '<hive>STATISTICS'; }
 <hive>'STORED'                             { return '<hive>STORED'; }
-<hive>STORED[ \t\n]+AS[ \t\n]+DIRECTORIES  { return '<hive>STORED_AS_DIRECTORIES'; }
+<hive>STORED\s+AS\s+DIRECTORIES            { return '<hive>STORED_AS_DIRECTORIES'; }
 <hive>'STRING'                             { return '<hive>STRING'; }
 <hive>'STRUCT'                             { return '<hive>STRUCT'; }
 <hive>'TABLES'                             { return '<hive>TABLES'; }
@@ -187,7 +187,7 @@
 <impala>'INIT_FN'                          { return '<impala>INIT_FN'; }
 <impala>'INPATH'                           { this.begin('hdfs'); return '<impala>INPATH'; }
 <impala>'LAST'                             { return '<impala>LAST'; }
-<impala>LIKE[ \t\n]+PARQUET                { this.begin('hdfs'); return '<impala>LIKE_PARQUET'; }
+<impala>LIKE\s+PARQUET                     { this.begin('hdfs'); return '<impala>LIKE_PARQUET'; }
 <impala>'LINES'                            { return '<impala>LINES'; }
 <impala>'LOAD'                             { determineCase(yytext); return '<impala>LOAD'; }
 <impala>'LOCATION'                         { this.begin('hdfs'); return '<impala>LOCATION'; }

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

@@ -1057,7 +1057,7 @@ ImpalaAggregateFunctionDefinition
    HdfsLocation OptionalImpalaInitFn ImpalaUpdateFn ImpalaMergeFn OptionalImpalaPrepareFn OptionalImpalaCloseFn OptionalImpalaSerializeFn OptionalImpalaFinalizeFn
  ;
 
-ImpalaAggregateFunctionDefinition
+ImpalaAggregateFunctionDefinition_EDIT
  : AnyCreate '<impala>AGGREGATE' 'CURSOR'
    {
      suggestKeywords(['FUNCTION']);

+ 80 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -24,6 +24,7 @@ DataDefinition_EDIT
 
 DropStatement
  : DropDatabaseStatement
+ | DropFunctionStatement
  | DropTableStatement
  | DropIndexStatement
  | DropMacroStatement
@@ -33,6 +34,7 @@ DropStatement
 
 DropStatement_EDIT
  : DropDatabaseStatement_EDIT
+ | DropFunctionStatement_EDIT
  | DropTableStatement_EDIT
  | DropIndexStatement_EDIT
  | DropMacroStatement_EDIT
@@ -79,6 +81,84 @@ DropDatabaseStatement_EDIT
    }
  ;
 
+DropFunctionStatement
+ : DropImpalaFunction
+ | DropHiveFunction
+ ;
+
+DropFunctionStatement_EDIT
+ : DropImpalaFunction_EDIT
+ | DropHiveFunction_EDIT
+ ;
+
+// OptionalAggregate is no go for look ahead reasons
+DropImpalaFunction
+ : 'DROP' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList
+ | 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList
+ ;
+
+DropImpalaFunction_EDIT
+ : 'DROP' '<impala>FUNCTION' OptionalIfExists 'CURSOR'
+   {
+     if (!$3) {
+       suggestKeywords(['IF EXISTS']);
+     }
+     suggestDatabases({ appendDot: true });
+   }
+ | 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists 'CURSOR'
+   {
+     if (!$4) {
+       suggestKeywords(['IF EXISTS']);
+     }
+     suggestDatabases({ appendDot: true });
+   }
+ | 'DROP' '<impala>FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList
+   {
+     if (!$3) {
+       suggestKeywords(['IF EXISTS']);
+     }
+   }
+ | 'DROP' '<impala>FUNCTION' OptionalIfExists_EDIT
+ | 'DROP' 'CURSOR' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList
+   {
+     suggestKeywords(['AGGREGATE']);
+   }
+ | 'DROP' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList_EDIT
+ | 'DROP' '<impala>AGGREGATE' 'CURSOR'
+   {
+     suggestKeywords(['FUNCTION']);
+   }
+ | 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList
+   {
+     if (!$4) {
+       suggestKeywords(['IF EXISTS']);
+     }
+   }
+ | 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists_EDIT
+ | 'DROP' '<impala>AGGREGATE' '<impala>FUNCTION' OptionalIfExists SchemaQualifiedTableIdentifier ParenthesizedImpalaArgumentList_EDIT
+ ;
+
+DropHiveFunction
+ : 'DROP' '<hive>FUNCTION' OptionalIfExists SchemaQualifiedTableIdentifier
+ ;
+
+DropHiveFunction_EDIT
+ : 'DROP' '<hive>FUNCTION' OptionalIfExists 'CURSOR'
+   {
+     if (!$3) {
+       suggestKeywords(['IF EXISTS']);
+     }
+   }
+ | 'DROP' '<hive>FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier
+   {
+     if (!$3) {
+       suggestKeywords(['IF EXISTS']);
+     }
+   }
+ | 'DROP' '<hive>FUNCTION' OptionalIfExists_EDIT
+ | 'DROP' '<hive>FUNCTION' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
+ ;
+
 DropTableStatement
  : 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier
    {

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


+ 169 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecDrop.js

@@ -158,6 +158,175 @@ define([
       });
     });
 
+    describe('DROP FUNCTION', function () {
+      describe('Hive specific', function () {
+        it('should handle "DROP FUNCTION IF EXISTS baa;', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION IF EXISTS baa;',
+            afterCursor: '',
+            dialect: 'hive',
+            containsKeywords: ['SELECT'],
+            noErrors: true,
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP ',
+            afterCursor: '',
+            dialect: 'hive',
+            containsKeywords: ['FUNCTION'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP FUNCTION |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION ',
+            afterCursor: '',
+            dialect: 'hive',
+            containsKeywords: ['IF EXISTS'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+      });
+
+      describe('Impala specific', function () {
+        it('should handle "DROP AGGREGATE FUNCTION IF EXISTS baa.boo(INT, STRING ...);', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP AGGREGATE FUNCTION IF EXISTS baa.boo(INT, STRING ...);',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['SELECT'],
+            noErrors: true,
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['AGGREGATE FUNCTION', 'FUNCTION'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP AGGREGATE |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP AGGREGATE ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['FUNCTION'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP FUNCTION |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['IF EXISTS'],
+            expectedResult: {
+              lowerCase: false,
+              suggestDatabases: { appendDot: true }
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP AGGREGATE FUNCTION |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP AGGREGATE FUNCTION ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['IF EXISTS'],
+            expectedResult: {
+              lowerCase: false,
+              suggestDatabases: { appendDot: true }
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP FUNCTION IF |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION IF ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['EXISTS'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest databases for "DROP FUNCTION IF EXISTS |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION IF EXISTS ',
+            afterCursor: '',
+            dialect: 'impala',
+            expectedResult: {
+              lowerCase: false,
+              suggestDatabases: { appendDot: true }
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP FUNCTION IF EXISTS baa.boo(|"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION IF EXISTS baa.boo(',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['INT'],
+            doesNotContainKeywords: ['...'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP FUNCTION IF EXISTS baa.boo(INT |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION IF EXISTS baa.boo(INT ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['...'],
+            doesNotContainKeywords: ['INT'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+
+        it('should suggest keywords for "DROP FUNCTION IF EXISTS baa.boo(INT, STRING, |"', function() {
+          assertAutoComplete({
+            beforeCursor: 'DROP FUNCTION IF EXISTS baa.boo(INT, STRING, ',
+            afterCursor: '',
+            dialect: 'impala',
+            containsKeywords: ['INT'],
+            doesNotContainKeywords: ['...'],
+            expectedResult: {
+              lowerCase: false
+            }
+          });
+        });
+      })
+    });
+
     describe('DROP INDEX', function () {
       it('should handle "DROP INDEX IF EXISTS baa ON baa.boo;|"', function() {
         assertAutoComplete({

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