Browse Source

HUE-4301 [editor] Autocomplete for Impala extract function

Johan Ahlen 9 năm trước cách đây
mục cha
commit
70f53f6

+ 97 - 44
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.jison

@@ -179,6 +179,8 @@
 CAST\(                              { return 'CAST('; }
 COUNT\(                             { return 'COUNT('; }
 SUM\(                               { return 'SUM('; }
+<impala>EXTRACT\(                   { return '<impala>EXTRACT('; }
+
 [A-Za-z][A-Za-z0-9_]*\(             { return 'UDF('; }
 
 [0-9]+                              { return 'UNSIGNED_INTEGER'; }
@@ -2370,17 +2372,19 @@ OptionalFilterClause
  ;
 
 UserDefinedFunction
- : CountFunction
- | SumFunction
+ : ArbitraryFunction
  | CastFunction
- | ArbitraryFunction
+ | CountFunction
+ | ExtractFunction
+ | SumFunction
  ;
 
 UserDefinedFunction_EDIT
- : CountFunction_EDIT
- | SumFunction_EDIT
+ : ArbitraryFunction_EDIT
  | CastFunction_EDIT
- | ArbitraryFunction_EDIT
+ | CountFunction_EDIT
+ | ExtractFunction_EDIT
+ | SumFunction_EDIT
  ;
 
 ArbitraryFunction
@@ -2407,8 +2411,48 @@ ArbitraryFunction_EDIT
  | 'UDF(' ValueExpressionList_EDIT RightParenthesisOrError
  ;
 
+CastFunction
+ : 'CAST(' ValueExpression AnyAs PrimitiveType ')'
+ | 'CAST(' ')'
+ ;
+
+CastFunction_EDIT
+ : 'CAST(' AnyCursor AnyAs PrimitiveType RightParenthesisOrError
+   {
+     valueExpressionSuggest();
+   }
+ | 'CAST(' AnyCursor AnyAs RightParenthesisOrError
+   {
+     valueExpressionSuggest();
+   }
+ | 'CAST(' AnyCursor RightParenthesisOrError
+   {
+     valueExpressionSuggest();
+   }
+ | 'CAST(' ValueExpression_EDIT AnyAs PrimitiveType RightParenthesisOrError
+ | 'CAST(' ValueExpression_EDIT AnyAs RightParenthesisOrError
+ | 'CAST(' ValueExpression_EDIT RightParenthesisOrError
+ | 'CAST(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
+   {
+     suggestKeywords(mergeSuggestKeywords({ suggestKeywords: ['AS'] }, $2).suggestKeywords);
+   }
+ | 'CAST(' ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     suggestKeywords(mergeSuggestKeywords({ suggestKeywords: ['AS'] }, $2).suggestKeywords);
+   }
+ | 'CAST(' ValueExpression AnyAs 'CURSOR' RightParenthesisOrError
+   {
+     suggestTypeKeywords();
+   }
+ | 'CAST(' AnyAs 'CURSOR' RightParenthesisOrError
+    {
+      suggestTypeKeywords();
+    }
+ ;
+
 CountFunction
  : 'COUNT(' '*' ')'
+ | 'COUNT(' ')'
  | 'COUNT(' OptionalAllOrDistinct ValueExpressionList ')'
  ;
 
@@ -2431,8 +2475,55 @@ CountFunction_EDIT
  | 'COUNT(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
  ;
 
+ExtractFunction
+ : '<impala>EXTRACT(' ValueExpression FromOrComma ValueExpression ')'
+ | '<impala>EXTRACT(' ')'
+ ;
+
+ExtractFunction_EDIT
+ : '<impala>EXTRACT(' AnyCursor FromOrComma ValueExpression RightParenthesisOrError
+    {
+      valueExpressionSuggest();
+    }
+ | '<impala>EXTRACT(' AnyCursor FromOrComma RightParenthesisOrError
+    {
+      valueExpressionSuggest();
+    }
+ | '<impala>EXTRACT(' AnyCursor RightParenthesisOrError
+    {
+      valueExpressionSuggest();
+    }
+ | '<impala>EXTRACT(' ValueExpression_EDIT FromOrComma ValueExpression RightParenthesisOrError
+ | '<impala>EXTRACT(' ValueExpression_EDIT FromOrComma RightParenthesisOrError
+ | '<impala>EXTRACT(' ValueExpression_EDIT RightParenthesisOrError
+ | '<impala>EXTRACT(' ValueExpression FromOrComma AnyCursor RightParenthesisOrError
+    {
+      valueExpressionSuggest();
+    }
+ | '<impala>EXTRACT(' FromOrComma AnyCursor RightParenthesisOrError
+    {
+      valueExpressionSuggest();
+    }
+ | '<impala>EXTRACT(' ValueExpression FromOrComma ValueExpression_EDIT RightParenthesisOrError
+ | '<impala>EXTRACT(' FromOrComma ValueExpression_EDIT RightParenthesisOrError
+ | '<impala>EXTRACT(' ValueExpression 'CURSOR' ValueExpression RightParenthesisOrError
+   {
+     suggestKeywords(mergeSuggestKeywords({ suggestKeywords: [',', 'FROM'] }, $2).suggestKeywords);
+   }
+ | '<impala>EXTRACT(' ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     suggestKeywords(mergeSuggestKeywords({ suggestKeywords: [',', 'FROM'] }, $2).suggestKeywords);
+   }
+ ;
+
+FromOrComma
+ : 'FROM'
+ | ','
+ ;
+
 SumFunction
  : 'SUM(' OptionalAllOrDistinct ValueExpression ')'
+ | 'SUM(' ')'
  ;
 
 SumFunction_EDIT
@@ -2454,44 +2545,6 @@ SumFunction_EDIT
  | 'SUM(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
  ;
 
-CastFunction
- : 'CAST(' ValueExpression AnyAs PrimitiveType ')'
- ;
-
-CastFunction_EDIT
- : 'CAST(' AnyCursor AnyAs PrimitiveType RightParenthesisOrError
-   {
-     valueExpressionSuggest();
-   }
- | 'CAST(' AnyCursor AnyAs RightParenthesisOrError
-   {
-     valueExpressionSuggest();
-   }
- | 'CAST(' AnyCursor RightParenthesisOrError
-   {
-     valueExpressionSuggest();
-   }
- | 'CAST(' ValueExpression_EDIT AnyAs PrimitiveType RightParenthesisOrError
- | 'CAST(' ValueExpression_EDIT AnyAs RightParenthesisOrError
- | 'CAST(' ValueExpression_EDIT RightParenthesisOrError
- | 'CAST(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
-   {
-     suggestKeywords(mergeSuggestKeywords({ suggestKeywords: ['AS'] }, $2).suggestKeywords);
-   }
- | 'CAST(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     suggestKeywords(mergeSuggestKeywords({ suggestKeywords: ['AS'] }, $2).suggestKeywords);
-   }
- | 'CAST(' ValueExpression AnyAs 'CURSOR' RightParenthesisOrError
-   {
-     suggestTypeKeywords();
-   }
- | 'CAST(' AnyAs 'CURSOR' RightParenthesisOrError
-    {
-      suggestTypeKeywords();
-    }
- ;
-
 WithinGroupSpecification
  : 'WITHIN' 'GROUP' '(' 'ORDER' 'BY' SortSpecificationList ')'
  ;

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js


+ 53 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecSelect.js

@@ -827,6 +827,59 @@ define([
         });
       });
 
+      it('should suggest columns for "SELECT extract(bla FROM |  FROM bar;"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SELECT extract(bla FROM ',
+          afterCursor: ' FROM bar;',
+          dialect: 'impala',
+          expectedResult: {
+            lowerCase: false,
+            suggestFunctions: true,
+            suggestColumns: { table: 'bar' }
+          }
+        });
+      });
+
+      it('should suggest columns for "SELECT extract(bla ,|  FROM bar;"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SELECT extract(bla ,',
+          afterCursor: ' FROM bar;',
+          dialect: 'impala',
+          expectedResult: {
+            lowerCase: false,
+            suggestFunctions: true,
+            suggestColumns: { table: 'bar' }
+          }
+        });
+      });
+
+      it('should suggest columns for "SELECT a, extract(bla FROM |)  FROM bar;"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SELECT a, extract(bla FROM ',
+          afterCursor: ') FROM bar;',
+          dialect: 'impala',
+          expectedResult: {
+            lowerCase: false,
+            suggestFunctions: true,
+            suggestColumns: { table: 'bar' }
+          }
+        });
+      });
+
+      it('should suggest columns for "SELECT extract(bla ,|)  FROM bar;"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SELECT extract(bla ,',
+          afterCursor: ') FROM bar;',
+          dialect: 'impala',
+          expectedResult: {
+            lowerCase: false,
+            suggestFunctions: true,
+            suggestColumns: { table: 'bar' }
+          }
+        });
+      });
+
+
       it('should suggest columns for "SELECT <GeneralSetFunction>(|) FROM testTable"', function () {
         var aggregateFunctions = [
           { name: 'AVG'},

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác