Przeglądaj źródła

HUE-9370 [editor] Extract UDF grammar to separate files

Johan Ahlen 5 lat temu
rodzic
commit
3c73d709cf
44 zmienionych plików z 1423 dodań i 2194 usunięć
  1. 2 395
      desktop/core/src/desktop/js/parse/jison/sql/calcite/sql_main.jison
  2. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/calcite/structure.json
  3. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/druid/structure.json
  4. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/elasticsearch/structure.json
  5. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/flink/structure.json
  6. 2 395
      desktop/core/src/desktop/js/parse/jison/sql/generic/sql_main.jison
  7. 409 0
      desktop/core/src/desktop/js/parse/jison/sql/generic/sql_udf.jison
  8. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/generic/structure.json
  9. 2 452
      desktop/core/src/desktop/js/parse/jison/sql/hive/sql_main.jison
  10. 466 0
      desktop/core/src/desktop/js/parse/jison/sql/hive/sql_udf.jison
  11. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/hive/structure.json
  12. 0 494
      desktop/core/src/desktop/js/parse/jison/sql/impala/sql_main.jison
  13. 510 0
      desktop/core/src/desktop/js/parse/jison/sql/impala/sql_udf.jison
  14. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/impala/structure.json
  15. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/ksql/structure.json
  16. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/phoenix/structure.json
  17. 2 452
      desktop/core/src/desktop/js/parse/jison/sql/presto/sql_main.jison
  18. 2 0
      desktop/core/src/desktop/js/parse/jison/sql/presto/structure.json
  19. 0 0
      desktop/core/src/desktop/js/parse/sql/calcite/calciteAutocompleteParser.js
  20. 0 0
      desktop/core/src/desktop/js/parse/sql/calcite/calciteSyntaxParser.js
  21. 0 0
      desktop/core/src/desktop/js/parse/sql/druid/druidAutocompleteParser.js
  22. 0 0
      desktop/core/src/desktop/js/parse/sql/druid/druidSyntaxParser.js
  23. 0 0
      desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js
  24. 0 0
      desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchSyntaxParser.js
  25. 0 0
      desktop/core/src/desktop/js/parse/sql/flink/flinkAutocompleteParser.js
  26. 0 0
      desktop/core/src/desktop/js/parse/sql/flink/flinkSyntaxParser.js
  27. 2 1
      desktop/core/src/desktop/js/parse/sql/flink/sqlParseSupport.js
  28. 0 0
      desktop/core/src/desktop/js/parse/sql/generic/genericAutocompleteParser.js
  29. 0 0
      desktop/core/src/desktop/js/parse/sql/generic/genericSyntaxParser.js
  30. 2 1
      desktop/core/src/desktop/js/parse/sql/generic/sqlParseSupport.js
  31. 0 0
      desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js
  32. 0 0
      desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js
  33. 0 0
      desktop/core/src/desktop/js/parse/sql/impala/impalaAutocompleteParser.js
  34. 0 0
      desktop/core/src/desktop/js/parse/sql/impala/impalaSyntaxParser.js
  35. 1 1
      desktop/core/src/desktop/js/parse/sql/impala/sqlParseSupport.js
  36. 0 0
      desktop/core/src/desktop/js/parse/sql/ksql/ksqlAutocompleteParser.js
  37. 0 0
      desktop/core/src/desktop/js/parse/sql/ksql/ksqlSyntaxParser.js
  38. 2 1
      desktop/core/src/desktop/js/parse/sql/ksql/sqlParseSupport.js
  39. 0 0
      desktop/core/src/desktop/js/parse/sql/phoenix/phoenixAutocompleteParser.js
  40. 0 0
      desktop/core/src/desktop/js/parse/sql/phoenix/phoenixSyntaxParser.js
  41. 2 1
      desktop/core/src/desktop/js/parse/sql/phoenix/sqlParseSupport.js
  42. 0 0
      desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js
  43. 0 0
      desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js
  44. 1 1
      desktop/core/src/desktop/js/parse/sql/presto/sqlParseSupport.js

+ 2 - 395
desktop/core/src/desktop/js/parse/jison/sql/calcite/sql_main.jison

@@ -1508,42 +1508,8 @@ InValueList
 
 NonParenthesizedValueExpressionPrimary
  : UnsignedValueSpecification
- | ColumnOrArbitraryFunctionRef             -> { types: ['COLREF'], columnReference: $1.chain }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
-   {
-     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
-     // with columnReference for functions like: db.udf(foo)
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.expression) {
-       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: fn, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-  {
-    parser.addFunctionLocation(@1, $1);
-    if ($2.expression) {
-      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-    } else {
-      $$ = { function: $1, types: ['UDFREF'] }
-    }
-  }
- | UserDefinedFunction
- | 'NULL'                      -> { types: [ 'NULL' ] }
+ | ColumnOrArbitraryFunctionRef  -> { types: ['COLREF'], columnReference: $1.chain }
+ | 'NULL'                        -> { types: [ 'NULL' ] }
  ;
 
 NonParenthesizedValueExpressionPrimary_EDIT
@@ -1556,36 +1522,6 @@ NonParenthesizedValueExpressionPrimary_EDIT
        $$ = { types: ['COLREF'], columnReference: $1 };
      }
    }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
-   {
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions(fn, $2.position);
-     }
-     $$ = { function: fn, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | UserDefinedFunction_EDIT
  ;
 
 ColumnOrArbitraryFunctionRef
@@ -2213,149 +2149,6 @@ OptionalCorrelationName_EDIT
  | 'AS' 'CURSOR'
  ;
 
-UserDefinedFunction
- : AggregateFunction OptionalOverClause
-   {
-     if (!$2) {
-       $1.suggestKeywords = ['OVER'];
-     }
-   }
- | AnalyticFunction OverClause
- | CastFunction
- ;
-
-UserDefinedFunction_EDIT
- : AggregateFunction_EDIT
- | AggregateFunction OptionalOverClause_EDIT
- | AnalyticFunction_EDIT
- | AnalyticFunction_EDIT OverClause
- | AnalyticFunction 'CURSOR'
-   {
-     parser.suggestKeywords(['OVER']);
-   }
- | AnalyticFunction OverClause_EDIT
- | CastFunction_EDIT
- ;
-
-ArbitraryFunction
- : RegularIdentifier ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- ;
-
-ArbitraryFunction_EDIT
- : RegularIdentifier ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ArbitraryFunctionName
- : 'ARRAY'
- | 'IF'
- | 'MAP'
- | 'TRUNCATE'
- ;
-
-ArbitraryFunctionRightPart
- : '(' ')'
- | '(' ValueExpressionList ')'  -> { expression: $2 }
- ;
-
-ArbitraryFunctionRightPart_EDIT
- : '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { position: 1 }
-   }
- | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-   }
- | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
- ;
-
-AggregateFunction
- : CountFunction
- | SumFunction
- | OtherAggregateFunction
- ;
-
-AggregateFunction_EDIT
- : CountFunction_EDIT
- | SumFunction_EDIT
- | OtherAggregateFunction_EDIT
- ;
-
-AnalyticFunction
- : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
- | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
- ;
-
-AnalyticFunction_EDIT
- : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     parser.applyArgumentTypesToSuggestions($1, $3.position);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OptionalOverClause
- :
- | OverClause
- ;
-
-OptionalOverClause_EDIT
- : OverClause_EDIT
- ;
-
-OverClause
- : 'OVER' RegularOrBacktickedIdentifier
- | 'OVER' WindowExpression
- ;
-
-OverClause_EDIT
- : 'OVER' WindowExpression_EDIT
- ;
-
 WindowExpression
  : '(' OptionalPartitionBy OptionalOrderByAndWindow ')'
  ;
@@ -2577,189 +2370,3 @@ HavingClause_EDIT
      parser.suggestSelectListAliases(true);
    }
  ;
-
-CastFunction
- : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
- ;
-
-CastFunction_EDIT
- : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ =  { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- ;
-
-CountFunction
- : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-CountFunction_EDIT
- : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords();
-     if (!$3) {
-       keywords.push('DISTINCT');
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords();
-       if (!$3) {
-         keywords.push('DISTINCT');
-       }
-       parser.suggestKeywords(keywords);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-OtherAggregateFunction_EDIT
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       if ($1.toLowerCase() === 'group_concat') {
-         keywords.push('ALL');
-       } else {
-         keywords.push('DISTINCT');
-       }
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords(true);
-       if (!$3) {
-         if ($1.toLowerCase() === 'group_concat') {
-           keywords.push('ALL');
-         } else {
-           keywords.push('DISTINCT');
-         }
-       }
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-       parser.suggestKeywords(keywords);
-     }
-     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, $4.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction_Type
- : 'AVG'
- | 'MAX'
- | 'MIN'
- | 'STDDEV_POP'
- | 'STDDEV_SAMP'
- | 'VAR_POP'
- | 'VAR_SAMP'
- | 'VARIANCE'
- ;
-
-FromOrComma
- : 'FROM'
- | ','
- ;
-
-SumFunction
- : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
- | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
- ;
-
-SumFunction_EDIT
- : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       keywords.push('DISTINCT');
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
-   {
-     if (parser.yy.result.suggestFunctions && ! parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, 1);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/calcite/structure.json

@@ -10,6 +10,7 @@
     "sql_main.jison",
     "../generic/sql_set.jison",
     "sql_select_stream.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -24,6 +25,7 @@
     "sql_main.jison",
     "../generic/sql_set.jison",
     "sql_select_stream.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/druid/structure.json

@@ -9,6 +9,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -22,6 +23,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/elasticsearch/structure.json

@@ -9,6 +9,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -22,6 +23,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/flink/structure.json

@@ -9,6 +9,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -22,6 +23,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

+ 2 - 395
desktop/core/src/desktop/js/parse/jison/sql/generic/sql_main.jison

@@ -1508,42 +1508,8 @@ InValueList
 
 NonParenthesizedValueExpressionPrimary
  : UnsignedValueSpecification
- | ColumnOrArbitraryFunctionRef             -> { types: ['COLREF'], columnReference: $1.chain }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
-   {
-     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
-     // with columnReference for functions like: db.udf(foo)
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.expression) {
-       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: fn, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-  {
-    parser.addFunctionLocation(@1, $1);
-    if ($2.expression) {
-      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-    } else {
-      $$ = { function: $1, types: ['UDFREF'] }
-    }
-  }
- | UserDefinedFunction
- | 'NULL'                      -> { types: [ 'NULL' ] }
+ | ColumnOrArbitraryFunctionRef  -> { types: ['COLREF'], columnReference: $1.chain }
+ | 'NULL'                        -> { types: [ 'NULL' ] }
  ;
 
 NonParenthesizedValueExpressionPrimary_EDIT
@@ -1556,36 +1522,6 @@ NonParenthesizedValueExpressionPrimary_EDIT
        $$ = { types: ['COLREF'], columnReference: $1 };
      }
    }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
-   {
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions(fn, $2.position);
-     }
-     $$ = { function: fn, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | UserDefinedFunction_EDIT
  ;
 
 ColumnOrArbitraryFunctionRef
@@ -2213,149 +2149,6 @@ OptionalCorrelationName_EDIT
  | 'AS' 'CURSOR'
  ;
 
-UserDefinedFunction
- : AggregateFunction OptionalOverClause
-   {
-     if (!$2) {
-       $1.suggestKeywords = ['OVER'];
-     }
-   }
- | AnalyticFunction OverClause
- | CastFunction
- ;
-
-UserDefinedFunction_EDIT
- : AggregateFunction_EDIT
- | AggregateFunction OptionalOverClause_EDIT
- | AnalyticFunction_EDIT
- | AnalyticFunction_EDIT OverClause
- | AnalyticFunction 'CURSOR'
-   {
-     parser.suggestKeywords(['OVER']);
-   }
- | AnalyticFunction OverClause_EDIT
- | CastFunction_EDIT
- ;
-
-ArbitraryFunction
- : RegularIdentifier ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- ;
-
-ArbitraryFunction_EDIT
- : RegularIdentifier ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ArbitraryFunctionName
- : 'ARRAY'
- | 'IF'
- | 'MAP'
- | 'TRUNCATE'
- ;
-
-ArbitraryFunctionRightPart
- : '(' ')'
- | '(' ValueExpressionList ')'  -> { expression: $2 }
- ;
-
-ArbitraryFunctionRightPart_EDIT
- : '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { position: 1 }
-   }
- | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-   }
- | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
- ;
-
-AggregateFunction
- : CountFunction
- | SumFunction
- | OtherAggregateFunction
- ;
-
-AggregateFunction_EDIT
- : CountFunction_EDIT
- | SumFunction_EDIT
- | OtherAggregateFunction_EDIT
- ;
-
-AnalyticFunction
- : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
- | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
- ;
-
-AnalyticFunction_EDIT
- : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     parser.applyArgumentTypesToSuggestions($1, $3.position);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OptionalOverClause
- :
- | OverClause
- ;
-
-OptionalOverClause_EDIT
- : OverClause_EDIT
- ;
-
-OverClause
- : 'OVER' RegularOrBacktickedIdentifier
- | 'OVER' WindowExpression
- ;
-
-OverClause_EDIT
- : 'OVER' WindowExpression_EDIT
- ;
-
 WindowExpression
  : '(' OptionalPartitionBy OptionalOrderByAndWindow ')'
  ;
@@ -2577,189 +2370,3 @@ HavingClause_EDIT
      parser.suggestSelectListAliases(true);
    }
  ;
-
-CastFunction
- : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
- ;
-
-CastFunction_EDIT
- : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ =  { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- ;
-
-CountFunction
- : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-CountFunction_EDIT
- : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords();
-     if (!$3) {
-       keywords.push('DISTINCT');
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords();
-       if (!$3) {
-         keywords.push('DISTINCT');
-       }
-       parser.suggestKeywords(keywords);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-OtherAggregateFunction_EDIT
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       if ($1.toLowerCase() === 'group_concat') {
-         keywords.push('ALL');
-       } else {
-         keywords.push('DISTINCT');
-       }
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords(true);
-       if (!$3) {
-         if ($1.toLowerCase() === 'group_concat') {
-           keywords.push('ALL');
-         } else {
-           keywords.push('DISTINCT');
-         }
-       }
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-       parser.suggestKeywords(keywords);
-     }
-     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, $4.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction_Type
- : 'AVG'
- | 'MAX'
- | 'MIN'
- | 'STDDEV_POP'
- | 'STDDEV_SAMP'
- | 'VAR_POP'
- | 'VAR_SAMP'
- | 'VARIANCE'
- ;
-
-FromOrComma
- : 'FROM'
- | ','
- ;
-
-SumFunction
- : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
- | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
- ;
-
-SumFunction_EDIT
- : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       keywords.push('DISTINCT');
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
-   {
-     if (parser.yy.result.suggestFunctions && ! parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, 1);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;

+ 409 - 0
desktop/core/src/desktop/js/parse/jison/sql/generic/sql_udf.jison

@@ -0,0 +1,409 @@
+// 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.
+
+NonParenthesizedValueExpressionPrimary
+ : ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
+   {
+     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
+     // with columnReference for functions like: db.udf(foo)
+     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
+     $1.lastLoc.type = 'function';
+     $1.lastLoc.function = fn;
+     $1.lastLoc.location = {
+       first_line: $1.lastLoc.location.first_line,
+       last_line: $1.lastLoc.location.last_line,
+       first_column: $1.lastLoc.location.first_column,
+       last_column: $1.lastLoc.location.last_column - 1
+     }
+     if ($1.lastLoc !== $1.firstLoc) {
+        $1.firstLoc.type = 'database';
+     } else {
+       delete $1.lastLoc.identifierChain;
+     }
+     if ($2.expression) {
+       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: fn, types: ['UDFREF'] }
+     }
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart
+  {
+    parser.addFunctionLocation(@1, $1);
+    if ($2.expression) {
+      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+    } else {
+      $$ = { function: $1, types: ['UDFREF'] }
+    }
+  }
+ | UserDefinedFunction
+ ;
+
+NonParenthesizedValueExpressionPrimary_EDIT
+ : ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
+   {
+     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
+     $1.lastLoc.type = 'function';
+     $1.lastLoc.function = fn;
+     $1.lastLoc.location = {
+       first_line: $1.lastLoc.location.first_line,
+       last_line: $1.lastLoc.location.last_line,
+       first_column: $1.lastLoc.location.first_column,
+       last_column: $1.lastLoc.location.last_column - 1
+     }
+     if ($1.lastLoc !== $1.firstLoc) {
+        $1.firstLoc.type = 'database';
+     } else {
+       delete $1.lastLoc.identifierChain;
+     }
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions(fn, $2.position);
+     }
+     $$ = { function: fn, types: ['UDFREF'] };
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | UserDefinedFunction_EDIT
+ ;
+
+UserDefinedFunction
+ : AggregateFunction OptionalOverClause
+   {
+     if (!$2) {
+       $1.suggestKeywords = ['OVER'];
+     }
+   }
+ | AnalyticFunction OverClause
+ | CastFunction
+ ;
+
+UserDefinedFunction_EDIT
+ : AggregateFunction_EDIT
+ | AggregateFunction OptionalOverClause_EDIT
+ | AnalyticFunction_EDIT
+ | AnalyticFunction_EDIT OverClause
+ | AnalyticFunction 'CURSOR'
+   {
+     parser.suggestKeywords(['OVER']);
+   }
+ | AnalyticFunction OverClause_EDIT
+ | CastFunction_EDIT
+ ;
+
+ArbitraryFunction
+ : RegularIdentifier ArbitraryFunctionRightPart
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.expression) {
+       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: $1, types: ['UDFREF'] }
+     }
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.expression) {
+       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: $1, types: ['UDFREF'] }
+     }
+   }
+ ;
+
+ArbitraryFunction_EDIT
+ : RegularIdentifier ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+ArbitraryFunctionName
+ : 'ARRAY'
+ | 'IF'
+ | 'MAP'
+ | 'TRUNCATE'
+ ;
+
+ArbitraryFunctionRightPart
+ : '(' ')'
+ | '(' ValueExpressionList ')'  -> { expression: $2 }
+ ;
+
+ArbitraryFunctionRightPart_EDIT
+ : '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { position: 1 }
+   }
+ | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3);
+   }
+ | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
+ ;
+
+AggregateFunction
+ : CountFunction
+ | SumFunction
+ | OtherAggregateFunction
+ ;
+
+AggregateFunction_EDIT
+ : CountFunction_EDIT
+ | SumFunction_EDIT
+ | OtherAggregateFunction_EDIT
+ ;
+
+AnalyticFunction
+ : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
+ | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
+ ;
+
+AnalyticFunction_EDIT
+ : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     parser.applyArgumentTypesToSuggestions($1, $3.position);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OptionalOverClause
+ :
+ | OverClause
+ ;
+
+OptionalOverClause_EDIT
+ : OverClause_EDIT
+ ;
+
+OverClause
+ : 'OVER' RegularOrBacktickedIdentifier
+ | 'OVER' WindowExpression
+ ;
+
+OverClause_EDIT
+ : 'OVER' WindowExpression_EDIT
+ ;
+
+CastFunction
+ : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
+ | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
+ ;
+
+CastFunction_EDIT
+ : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ $5.toUpperCase() ] };
+   }
+ | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
+ | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
+ | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
+ | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
+     $$ =  { types: [ $5.toUpperCase() ] };
+   }
+ | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(parser.getTypeKeywords());
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(parser.getTypeKeywords());
+     $$ = { types: [ 'T' ] };
+   }
+ ;
+
+CountFunction
+ : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
+ | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
+ ;
+
+CountFunction_EDIT
+ : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords();
+     if (!$3) {
+       keywords.push('DISTINCT');
+       if (parser.yy.result.suggestKeywords) {
+         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       }
+     }
+     parser.suggestKeywords(keywords);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords();
+       if (!$3) {
+         keywords.push('DISTINCT');
+       }
+       parser.suggestKeywords(keywords);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OtherAggregateFunction
+ : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
+ ;
+
+OtherAggregateFunction_EDIT
+ : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords(true);
+     if (!$3) {
+       if ($1.toLowerCase() === 'group_concat') {
+         keywords.push('ALL');
+       } else {
+         keywords.push('DISTINCT');
+       }
+     }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords(true);
+       if (!$3) {
+         if ($1.toLowerCase() === 'group_concat') {
+           keywords.push('ALL');
+         } else {
+           keywords.push('DISTINCT');
+         }
+       }
+       if (parser.yy.result.suggestKeywords) {
+         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       }
+       parser.suggestKeywords(keywords);
+     }
+     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
+       parser.applyArgumentTypesToSuggestions($1, $4.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OtherAggregateFunction_Type
+ : 'AVG'
+ | 'MAX'
+ | 'MIN'
+ | 'STDDEV_POP'
+ | 'STDDEV_SAMP'
+ | 'VAR_POP'
+ | 'VAR_SAMP'
+ | 'VARIANCE'
+ ;
+
+SumFunction
+ : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
+ | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
+ ;
+
+SumFunction_EDIT
+ : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     var keywords = parser.getSelectListKeywords(true);
+     if (!$3) {
+       keywords.push('DISTINCT');
+     }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
+   {
+     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
+       parser.applyArgumentTypesToSuggestions($1, 1);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/generic/structure.json

@@ -9,6 +9,7 @@
     "sql_insert.jison",
     "sql_main.jison",
     "sql_set.jison",
+    "sql_udf.jison",
     "sql_update.jison",
     "sql_use.jison",
     "sql_valueExpression.jison",
@@ -22,6 +23,7 @@
     "sql_insert.jison",
     "sql_main.jison",
     "sql_set.jison",
+    "sql_udf.jison",
     "sql_update.jison",
     "sql_use.jison",
     "sql_valueExpression.jison",

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

@@ -2239,42 +2239,8 @@ InValueList
 
 NonParenthesizedValueExpressionPrimary
  : UnsignedValueSpecification
- | ColumnOrArbitraryFunctionRef             -> { types: ['COLREF'], columnReference: $1.chain }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
-   {
-     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
-     // with columnReference for functions like: db.udf(foo)
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.expression) {
-       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: fn, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-  {
-    parser.addFunctionLocation(@1, $1);
-    if ($2.expression) {
-      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-    } else {
-      $$ = { function: $1, types: ['UDFREF'] }
-    }
-  }
- | UserDefinedFunction
- | 'NULL'                      -> { types: [ 'NULL' ] }
+ | ColumnOrArbitraryFunctionRef  -> { types: ['COLREF'], columnReference: $1.chain }
+ | 'NULL'                        -> { types: [ 'NULL' ] }
  ;
 
 NonParenthesizedValueExpressionPrimary_EDIT
@@ -2287,36 +2253,6 @@ NonParenthesizedValueExpressionPrimary_EDIT
        $$ = { types: ['COLREF'], columnReference: $1 };
      }
    }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
-   {
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions(fn, $2.position);
-     }
-     $$ = { function: fn, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | UserDefinedFunction_EDIT
  ;
 
 ColumnOrArbitraryFunctionRef
@@ -3004,152 +2940,6 @@ OptionalLateralViews_EDIT
  : OptionalLateralViews LateralView_EDIT OptionalLateralViews
  ;
 
-UserDefinedFunction
- : AggregateFunction OptionalOverClause
-   {
-     if (!$2) {
-       $1.suggestKeywords = ['OVER'];
-     }
-   }
- | AnalyticFunction OverClause
- | CastFunction
- | ExtractFunction
- ;
-
-UserDefinedFunction_EDIT
- : AggregateFunction_EDIT
- | AggregateFunction OptionalOverClause_EDIT
- | AnalyticFunction_EDIT
- | AnalyticFunction_EDIT OverClause
- | AnalyticFunction 'CURSOR'
-   {
-     parser.suggestKeywords(['OVER']);
-   }
- | AnalyticFunction OverClause_EDIT
- | CastFunction_EDIT
- | ExtractFunction_EDIT
- ;
-
-ArbitraryFunction
- : RegularIdentifier ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- ;
-
-ArbitraryFunction_EDIT
- : RegularIdentifier ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ArbitraryFunctionName
- : 'ARRAY'
- | 'BINARY'
- | 'IF'
- | 'MAP'
- | 'TRUNCATE'
- ;
-
-ArbitraryFunctionRightPart
- : '(' ')'
- | '(' ValueExpressionList ')'  -> { expression: $2 }
- ;
-
-ArbitraryFunctionRightPart_EDIT
- : '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { position: 1 }
-   }
- | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-   }
- | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
- ;
-
-AggregateFunction
- : CountFunction
- | SumFunction
- | OtherAggregateFunction
- ;
-
-AggregateFunction_EDIT
- : CountFunction_EDIT
- | SumFunction_EDIT
- | OtherAggregateFunction_EDIT
- ;
-
-AnalyticFunction
- : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
- | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
- ;
-
-AnalyticFunction_EDIT
- : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     parser.applyArgumentTypesToSuggestions($1, $3.position);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OptionalOverClause
- :
- | OverClause
- ;
-
-OptionalOverClause_EDIT
- : OverClause_EDIT
- ;
-
-OverClause
- : 'OVER' RegularOrBacktickedIdentifier
- | 'OVER' WindowExpression
- ;
-
-OverClause_EDIT
- : 'OVER' WindowExpression_EDIT
- ;
-
 WindowExpression
  : '(' OptionalPartitionBy OptionalOrderByAndWindow ')'
  ;
@@ -3394,246 +3184,6 @@ WindowClause_EDIT
  | 'WINDOW' RegularOrBacktickedIdentifier 'AS' WindowExpression_EDIT
  ;
 
-CastFunction
- : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
- ;
-
-CastFunction_EDIT
- : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ =  { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- ;
-
-CountFunction
- : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-CountFunction_EDIT
- : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords();
-     if (!$3) {
-       keywords.push('DISTINCT');
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords();
-       if (!$3) {
-         keywords.push('DISTINCT');
-       }
-       parser.suggestKeywords(keywords);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ExtractFunction
- : 'EXTRACT' '(' DateField 'FROM' ValueExpression ')'  -> { types: ['INT', 'INTEGER'] }
- ;
-
-ExtractFunction_EDIT
- : 'EXTRACT' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.suggestKeywords(['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR']);
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(['FROM']);
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'FROM' 'CURSOR' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'FROM' ValueExpression_EDIT RightParenthesisOrError  -> { types: ['INT', 'INTEGER'] }
- | 'EXTRACT' '(' AnyCursor 'FROM' ValueExpression RightParenthesisOrError
-   {
-      parser.suggestKeywords(['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR']);
-      $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'CURSOR' ValueExpression RightParenthesisOrError
-   {
-     parser.suggestKeywords(['FROM']);
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- ;
-
-DateField
- : 'DAY'
- | 'DAYOFWEEK'
- | 'HOUR'
- | 'MINUTE'
- | 'MONTH'
- | 'QUARTER'
- | 'SECOND'
- | 'WEEK'
- | 'YEAR'
- ;
-
-OtherAggregateFunction
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-OtherAggregateFunction_EDIT
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       if ($1.toLowerCase() === 'group_concat') {
-         keywords.push('ALL');
-       } else {
-         keywords.push('DISTINCT');
-       }
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords(true);
-       if (!$3) {
-         if ($1.toLowerCase() === 'group_concat') {
-           keywords.push('ALL');
-         } else {
-           keywords.push('DISTINCT');
-         }
-       }
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-       parser.suggestKeywords(keywords);
-     }
-     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, $4.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction_Type
- : 'AVG'
- | 'COLLECT_LIST'
- | 'COLLECT_SET'
- | 'CORR'
- | 'COVAR_POP'
- | 'COVAR_SAMP'
- | 'HISTOGRAM_NUMERIC'
- | 'MAX'
- | 'MIN'
- | 'NTILE'
- | 'PERCENTILE'
- | 'PERCENTILE_APPROX'
- | 'STDDEV_POP'
- | 'STDDEV_SAMP'
- | 'VAR_POP'
- | 'VAR_SAMP'
- | 'VARIANCE'
- ;
-
-FromOrComma
- : 'FROM'
- | ','
- ;
-
-SumFunction
- : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
- | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
- ;
-
-SumFunction_EDIT
- : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       keywords.push('DISTINCT');
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
-   {
-     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, 1);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
 LateralView
  : 'LATERAL' 'VIEW' OptionalOuter ArbitraryFunction RegularOrBacktickedIdentifier LateralViewColumnAliases  -> { lateralView: { udtf: $4, tableAlias: $5, columnAliases: $6 }}
  | 'LATERAL' 'VIEW' OptionalOuter ArbitraryFunction RegularOrBacktickedIdentifier

+ 466 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_udf.jison

@@ -0,0 +1,466 @@
+// 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.
+
+NonParenthesizedValueExpressionPrimary
+ : ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
+   {
+     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
+     // with columnReference for functions like: db.udf(foo)
+     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
+     $1.lastLoc.type = 'function';
+     $1.lastLoc.function = fn;
+     $1.lastLoc.location = {
+       first_line: $1.lastLoc.location.first_line,
+       last_line: $1.lastLoc.location.last_line,
+       first_column: $1.lastLoc.location.first_column,
+       last_column: $1.lastLoc.location.last_column - 1
+     }
+     if ($1.lastLoc !== $1.firstLoc) {
+        $1.firstLoc.type = 'database';
+     } else {
+       delete $1.lastLoc.identifierChain;
+     }
+     if ($2.expression) {
+       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: fn, types: ['UDFREF'] }
+     }
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart
+  {
+    parser.addFunctionLocation(@1, $1);
+    if ($2.expression) {
+      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+    } else {
+      $$ = { function: $1, types: ['UDFREF'] }
+    }
+  }
+ | UserDefinedFunction
+ ;
+
+NonParenthesizedValueExpressionPrimary_EDIT
+ : ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
+   {
+     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
+     $1.lastLoc.type = 'function';
+     $1.lastLoc.function = fn;
+     $1.lastLoc.location = {
+       first_line: $1.lastLoc.location.first_line,
+       last_line: $1.lastLoc.location.last_line,
+       first_column: $1.lastLoc.location.first_column,
+       last_column: $1.lastLoc.location.last_column - 1
+     }
+     if ($1.lastLoc !== $1.firstLoc) {
+        $1.firstLoc.type = 'database';
+     } else {
+       delete $1.lastLoc.identifierChain;
+     }
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions(fn, $2.position);
+     }
+     $$ = { function: fn, types: ['UDFREF'] };
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | UserDefinedFunction_EDIT
+ ;
+
+UserDefinedFunction
+ : AggregateFunction OptionalOverClause
+   {
+     if (!$2) {
+       $1.suggestKeywords = ['OVER'];
+     }
+   }
+ | AnalyticFunction OverClause
+ | CastFunction
+ | ExtractFunction
+ ;
+
+UserDefinedFunction_EDIT
+ : AggregateFunction_EDIT
+ | AggregateFunction OptionalOverClause_EDIT
+ | AnalyticFunction_EDIT
+ | AnalyticFunction_EDIT OverClause
+ | AnalyticFunction 'CURSOR'
+   {
+     parser.suggestKeywords(['OVER']);
+   }
+ | AnalyticFunction OverClause_EDIT
+ | CastFunction_EDIT
+ | ExtractFunction_EDIT
+ ;
+
+ArbitraryFunction
+ : RegularIdentifier ArbitraryFunctionRightPart
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.expression) {
+       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: $1, types: ['UDFREF'] }
+     }
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.expression) {
+       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: $1, types: ['UDFREF'] }
+     }
+   }
+ ;
+
+ArbitraryFunction_EDIT
+ : RegularIdentifier ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+ArbitraryFunctionName
+ : 'ARRAY'
+ | 'BINARY'
+ | 'IF'
+ | 'MAP'
+ | 'TRUNCATE'
+ ;
+
+ArbitraryFunctionRightPart
+ : '(' ')'
+ | '(' ValueExpressionList ')'  -> { expression: $2 }
+ ;
+
+ArbitraryFunctionRightPart_EDIT
+ : '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { position: 1 }
+   }
+ | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3);
+   }
+ | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
+ ;
+
+AggregateFunction
+ : CountFunction
+ | SumFunction
+ | OtherAggregateFunction
+ ;
+
+AggregateFunction_EDIT
+ : CountFunction_EDIT
+ | SumFunction_EDIT
+ | OtherAggregateFunction_EDIT
+ ;
+
+AnalyticFunction
+ : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
+ | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
+ ;
+
+AnalyticFunction_EDIT
+ : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     parser.applyArgumentTypesToSuggestions($1, $3.position);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OptionalOverClause
+ :
+ | OverClause
+ ;
+
+OptionalOverClause_EDIT
+ : OverClause_EDIT
+ ;
+
+OverClause
+ : 'OVER' RegularOrBacktickedIdentifier
+ | 'OVER' WindowExpression
+ ;
+
+OverClause_EDIT
+ : 'OVER' WindowExpression_EDIT
+ ;
+
+CastFunction
+ : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
+ | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
+ ;
+
+CastFunction_EDIT
+ : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ $5.toUpperCase() ] };
+   }
+ | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
+ | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
+ | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
+ | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
+     $$ =  { types: [ $5.toUpperCase() ] };
+   }
+ | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(parser.getTypeKeywords());
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(parser.getTypeKeywords());
+     $$ = { types: [ 'T' ] };
+   }
+ ;
+
+CountFunction
+ : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
+ | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
+ ;
+
+CountFunction_EDIT
+ : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords();
+     if (!$3) {
+       keywords.push('DISTINCT');
+       if (parser.yy.result.suggestKeywords) {
+         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       }
+     }
+     parser.suggestKeywords(keywords);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords();
+       if (!$3) {
+         keywords.push('DISTINCT');
+       }
+       parser.suggestKeywords(keywords);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+ExtractFunction
+ : 'EXTRACT' '(' DateField 'FROM' ValueExpression ')'  -> { types: ['INT', 'INTEGER'] }
+ ;
+
+ExtractFunction_EDIT
+ : 'EXTRACT' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.suggestKeywords(['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR']);
+     $$ = { types: ['INT', 'INTEGER'] }
+   }
+ | 'EXTRACT' '(' DateField 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(['FROM']);
+     $$ = { types: ['INT', 'INTEGER'] }
+   }
+ | 'EXTRACT' '(' DateField 'FROM' 'CURSOR' RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: ['INT', 'INTEGER'] }
+   }
+ | 'EXTRACT' '(' DateField 'FROM' ValueExpression_EDIT RightParenthesisOrError  -> { types: ['INT', 'INTEGER'] }
+ | 'EXTRACT' '(' AnyCursor 'FROM' ValueExpression RightParenthesisOrError
+   {
+      parser.suggestKeywords(['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR']);
+      $$ = { types: ['INT', 'INTEGER'] }
+   }
+ | 'EXTRACT' '(' DateField 'CURSOR' ValueExpression RightParenthesisOrError
+   {
+     parser.suggestKeywords(['FROM']);
+     $$ = { types: ['INT', 'INTEGER'] }
+   }
+ ;
+
+DateField
+ : 'DAY'
+ | 'DAYOFWEEK'
+ | 'HOUR'
+ | 'MINUTE'
+ | 'MONTH'
+ | 'QUARTER'
+ | 'SECOND'
+ | 'WEEK'
+ | 'YEAR'
+ ;
+
+OtherAggregateFunction
+ : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
+ ;
+
+OtherAggregateFunction_EDIT
+ : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords(true);
+     if (!$3) {
+       if ($1.toLowerCase() === 'group_concat') {
+         keywords.push('ALL');
+       } else {
+         keywords.push('DISTINCT');
+       }
+     }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords(true);
+       if (!$3) {
+         if ($1.toLowerCase() === 'group_concat') {
+           keywords.push('ALL');
+         } else {
+           keywords.push('DISTINCT');
+         }
+       }
+       if (parser.yy.result.suggestKeywords) {
+         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       }
+       parser.suggestKeywords(keywords);
+     }
+     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
+       parser.applyArgumentTypesToSuggestions($1, $4.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OtherAggregateFunction_Type
+ : 'AVG'
+ | 'COLLECT_LIST'
+ | 'COLLECT_SET'
+ | 'CORR'
+ | 'COVAR_POP'
+ | 'COVAR_SAMP'
+ | 'HISTOGRAM_NUMERIC'
+ | 'MAX'
+ | 'MIN'
+ | 'NTILE'
+ | 'PERCENTILE'
+ | 'PERCENTILE_APPROX'
+ | 'STDDEV_POP'
+ | 'STDDEV_SAMP'
+ | 'VAR_POP'
+ | 'VAR_SAMP'
+ | 'VARIANCE'
+ ;
+
+SumFunction
+ : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
+ | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
+ ;
+
+SumFunction_EDIT
+ : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     var keywords = parser.getSelectListKeywords(true);
+     if (!$3) {
+       keywords.push('DISTINCT');
+     }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
+   {
+     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
+       parser.applyArgumentTypesToSuggestions($1, 1);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/structure.json

@@ -18,6 +18,7 @@
     "sql_set.jison",
     "show/sql_show.jison",
     "show/sql_show_materialized_views.jison",
+    "sql_udf.jison",
     "sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -40,6 +41,7 @@
     "sql_set.jison",
     "show/sql_show.jison",
     "show/sql_show_materialized_views.jison",
+    "sql_udf.jison",
     "sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

+ 0 - 494
desktop/core/src/desktop/js/parse/jison/sql/impala/sql_main.jison

@@ -2173,40 +2173,6 @@ InValueList
 NonParenthesizedValueExpressionPrimary
  : UnsignedValueSpecification
  | ColumnOrArbitraryFunctionRef             -> { types: ['COLREF'], columnReference: $1.chain }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
-   {
-     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
-     // with columnReference for functions like: db.udf(foo)
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.expression) {
-       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: fn, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-  {
-    parser.addFunctionLocation(@1, $1);
-    if ($2.expression) {
-      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-    } else {
-      $$ = { function: $1, types: ['UDFREF'] }
-    }
-  }
- | UserDefinedFunction
  | 'NULL'                      -> { types: [ 'NULL' ] }
  | IntervalSpecification       -> { types: [ 'TIMESTAMP' ] }
  ;
@@ -2221,36 +2187,6 @@ NonParenthesizedValueExpressionPrimary_EDIT
        $$ = { types: ['COLREF'], columnReference: $1 };
      }
    }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
-   {
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions(fn, $2.position);
-     }
-     $$ = { function: fn, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | UserDefinedFunction_EDIT
  | IntervalSpecification_EDIT
  ;
 
@@ -2930,153 +2866,6 @@ OptionalCorrelationName_EDIT
  | 'AS' 'CURSOR'
  ;
 
-UserDefinedFunction
- : AggregateFunction OptionalOverClause
-   {
-     if (!$2) {
-       $1.suggestKeywords = ['OVER'];
-     }
-   }
- | AnalyticFunction OverClause
- | CastFunction
- | ExtractFunction
- ;
-
-UserDefinedFunction_EDIT
- : AggregateFunction_EDIT
- | AggregateFunction OptionalOverClause_EDIT
- | AnalyticFunction_EDIT
- | AnalyticFunction_EDIT OverClause
- | AnalyticFunction 'CURSOR'
-   {
-     parser.suggestKeywords(['OVER']);
-   }
- | AnalyticFunction OverClause_EDIT
- | CastFunction_EDIT
- | ExtractFunction_EDIT
- ;
-
-ArbitraryFunction
- : RegularIdentifier ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- ;
-
-ArbitraryFunction_EDIT
- : RegularIdentifier ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ArbitraryFunctionName
- : 'IF'
- | 'ARRAY'
- | 'MAP'
- | 'REPLACE'
- | 'TRUNCATE'
- | 'USER'
- ;
-
-ArbitraryFunctionRightPart
- : '(' ')'
- | '(' ValueExpressionList ')'  -> { expression: $2 }
- ;
-
-ArbitraryFunctionRightPart_EDIT
- : '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { position: 1 }
-   }
- | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-   }
- | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
- ;
-
-AggregateFunction
- : CountFunction
- | SumFunction
- | OtherAggregateFunction
- ;
-
-AggregateFunction_EDIT
- : CountFunction_EDIT
- | SumFunction_EDIT
- | OtherAggregateFunction_EDIT
- ;
-
-AnalyticFunction
- : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
- | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
- ;
-
-AnalyticFunction_EDIT
- : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     parser.applyArgumentTypesToSuggestions($1, $3.position);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OptionalOverClause
- :
- | OverClause
- ;
-
-OptionalOverClause_EDIT
- : OverClause_EDIT
- ;
-
-OverClause
- : 'OVER' RegularOrBacktickedIdentifier
- | 'OVER' WindowExpression
- ;
-
-OverClause_EDIT
- : 'OVER' WindowExpression_EDIT
- ;
-
 WindowExpression
  : '(' OptionalPartitionBy OptionalOrderByAndWindow ')'
  ;
@@ -3298,286 +3087,3 @@ HavingClause_EDIT
      parser.suggestSelectListAliases(true);
    }
  ;
-
-CastFunction
- : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
- ;
-
-CastFunction_EDIT
- : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ =  { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- ;
-
-CountFunction
- : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-CountFunction_EDIT
- : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords();
-     if (!$3) {
-       keywords.push('DISTINCT');
-       keywords.push('ALL');
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords();
-       if (!$3) {
-         keywords.push('DISTINCT');
-         keywords.push('ALL');
-       }
-       parser.suggestKeywords(keywords);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-OtherAggregateFunction_EDIT
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       if ($1.toLowerCase() === 'group_concat') {
-         keywords.push('ALL');
-       } else {
-         keywords.push('ALL');
-         keywords.push('DISTINCT');
-       }
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords(true);
-       if (!$3) {
-         if ($1.toLowerCase() === 'group_concat') {
-           keywords.push('ALL');
-         } else {
-           keywords.push('ALL');
-           keywords.push('DISTINCT');
-         }
-       }
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-       parser.suggestKeywords(keywords);
-     }
-     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, $4.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction_Type
- : 'APPX_MEDIAN'
- | 'AVG'
- | 'GROUP_CONCAT'
- | 'STDDEV'
- | 'STDDEV_POP'
- | 'STDDEV_SAMP'
- | 'MAX'
- | 'MIN'
- | 'NDV'
- | 'VARIANCE'
- | 'VARIANCE_POP'
- | 'VARIANCE_SAMP'
- | 'VAR_POP'
- | 'VAR_SAMP'
- ;
-
-ExtractFunction
- : 'EXTRACT' '(' ValueExpression FromOrComma ValueExpression ')'
- | 'EXTRACT' '(' ')'
- ;
-
-ExtractFunction_EDIT
- : 'EXTRACT' '(' AnyCursor FromOrComma ValueExpression RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' AnyCursor FromOrComma RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyTypeToSuggestions({ types: ['STRING', 'TIMESTAMP'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression_EDIT FromOrComma ValueExpression RightParenthesisOrError
-   {
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression_EDIT FromOrComma RightParenthesisOrError
-   {
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression_EDIT RightParenthesisOrError
-   {
-     parser.applyTypeToSuggestions({ types: ['STRING', 'TIMESTAMP'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression FromOrComma AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' FromOrComma AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression FromOrComma ValueExpression_EDIT RightParenthesisOrError
-   {
-     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' FromOrComma ValueExpression_EDIT RightParenthesisOrError
-   {
-    parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression 'CURSOR' ValueExpression RightParenthesisOrError
-   {
-     if ($3.types[0] === 'STRING') {
-       parser.suggestValueExpressionKeywords($3, ['FROM']);
-     } else {
-       parser.suggestValueExpressionKeywords($3);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'EXTRACT' '(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     if ($3.types[0] === 'STRING') {
-       parser.suggestValueExpressionKeywords($3, ['FROM']);
-     } else {
-       parser.suggestValueExpressionKeywords($3);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-FromOrComma
- : 'FROM'
- | ','
- ;
-
-SumFunction
- : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
- | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
- ;
-
-SumFunction_EDIT
- : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       keywords.push('DISTINCT');
-       keywords.push('ALL');
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
-   {
-     if (parser.yy.result.suggestFunctions && ! parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, 1);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OptionalOuter
- :
- | 'OUTER'
- ;

+ 510 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/sql_udf.jison

@@ -0,0 +1,510 @@
+// 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.
+
+NonParenthesizedValueExpressionPrimary
+ : ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
+   {
+     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
+     // with columnReference for functions like: db.udf(foo)
+     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
+     $1.lastLoc.type = 'function';
+     $1.lastLoc.function = fn;
+     $1.lastLoc.location = {
+       first_line: $1.lastLoc.location.first_line,
+       last_line: $1.lastLoc.location.last_line,
+       first_column: $1.lastLoc.location.first_column,
+       last_column: $1.lastLoc.location.last_column - 1
+     }
+     if ($1.lastLoc !== $1.firstLoc) {
+        $1.firstLoc.type = 'database';
+     } else {
+       delete $1.lastLoc.identifierChain;
+     }
+     if ($2.expression) {
+       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: fn, types: ['UDFREF'] }
+     }
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart
+  {
+    parser.addFunctionLocation(@1, $1);
+    if ($2.expression) {
+      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+    } else {
+      $$ = { function: $1, types: ['UDFREF'] }
+    }
+  }
+ | UserDefinedFunction
+ ;
+
+NonParenthesizedValueExpressionPrimary_EDIT
+ : ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
+   {
+     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
+     $1.lastLoc.type = 'function';
+     $1.lastLoc.function = fn;
+     $1.lastLoc.location = {
+       first_line: $1.lastLoc.location.first_line,
+       last_line: $1.lastLoc.location.last_line,
+       first_column: $1.lastLoc.location.first_column,
+       last_column: $1.lastLoc.location.last_column - 1
+     }
+     if ($1.lastLoc !== $1.firstLoc) {
+        $1.firstLoc.type = 'database';
+     } else {
+       delete $1.lastLoc.identifierChain;
+     }
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions(fn, $2.position);
+     }
+     $$ = { function: fn, types: ['UDFREF'] };
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | UserDefinedFunction_EDIT
+ ;
+
+UserDefinedFunction
+ : AggregateFunction OptionalOverClause
+   {
+     if (!$2) {
+       $1.suggestKeywords = ['OVER'];
+     }
+   }
+ | AnalyticFunction OverClause
+ | CastFunction
+ | ExtractFunction
+ ;
+
+UserDefinedFunction_EDIT
+ : AggregateFunction_EDIT
+ | AggregateFunction OptionalOverClause_EDIT
+ | AnalyticFunction_EDIT
+ | AnalyticFunction_EDIT OverClause
+ | AnalyticFunction 'CURSOR'
+   {
+     parser.suggestKeywords(['OVER']);
+   }
+ | AnalyticFunction OverClause_EDIT
+ | CastFunction_EDIT
+ | ExtractFunction_EDIT
+ ;
+
+ArbitraryFunction
+ : RegularIdentifier ArbitraryFunctionRightPart
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.expression) {
+       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: $1, types: ['UDFREF'] }
+     }
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.expression) {
+       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
+     } else {
+       $$ = { function: $1, types: ['UDFREF'] }
+     }
+   }
+ ;
+
+ArbitraryFunction_EDIT
+ : RegularIdentifier ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
+   {
+     parser.addFunctionLocation(@1, $1);
+     if ($2.position) {
+       parser.applyArgumentTypesToSuggestions($1, $2.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+ArbitraryFunctionName
+ : 'IF'
+ | 'ARRAY'
+ | 'MAP'
+ | 'REPLACE'
+ | 'TRUNCATE'
+ | 'USER'
+ ;
+
+ArbitraryFunctionRightPart
+ : '(' ')'
+ | '(' ValueExpressionList ')'  -> { expression: $2 }
+ ;
+
+ArbitraryFunctionRightPart_EDIT
+ : '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { position: 1 }
+   }
+ | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3);
+   }
+ | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
+ ;
+
+AggregateFunction
+ : CountFunction
+ | SumFunction
+ | OtherAggregateFunction
+ ;
+
+AggregateFunction_EDIT
+ : CountFunction_EDIT
+ | SumFunction_EDIT
+ | OtherAggregateFunction_EDIT
+ ;
+
+AnalyticFunction
+ : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
+ | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
+ ;
+
+AnalyticFunction_EDIT
+ : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     parser.applyArgumentTypesToSuggestions($1, $3.position);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OptionalOverClause
+ :
+ | OverClause
+ ;
+
+OptionalOverClause_EDIT
+ : OverClause_EDIT
+ ;
+
+OverClause
+ : 'OVER' RegularOrBacktickedIdentifier
+ | 'OVER' WindowExpression
+ ;
+
+OverClause_EDIT
+ : 'OVER' WindowExpression_EDIT
+ ;
+
+CastFunction
+ : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
+ | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
+ ;
+
+CastFunction_EDIT
+ : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ $5.toUpperCase() ] };
+   }
+ | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
+ | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
+ | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
+ | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
+     $$ =  { types: [ $5.toUpperCase() ] };
+   }
+ | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(parser.getTypeKeywords());
+     $$ = { types: [ 'T' ] };
+   }
+ | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(parser.getTypeKeywords());
+     $$ = { types: [ 'T' ] };
+   }
+ ;
+
+CountFunction
+ : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
+ | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
+ ;
+
+CountFunction_EDIT
+ : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords();
+     if (!$3) {
+       keywords.push('DISTINCT');
+       keywords.push('ALL');
+       if (parser.yy.result.suggestKeywords) {
+         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       }
+     }
+     parser.suggestKeywords(keywords);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords();
+       if (!$3) {
+         keywords.push('DISTINCT');
+         keywords.push('ALL');
+       }
+       parser.suggestKeywords(keywords);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OtherAggregateFunction
+ : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
+ ;
+
+OtherAggregateFunction_EDIT
+ : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords(true);
+     if (!$3) {
+       if ($1.toLowerCase() === 'group_concat') {
+         keywords.push('ALL');
+       } else {
+         keywords.push('ALL');
+         keywords.push('DISTINCT');
+       }
+     }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
+   {
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords(true);
+       if (!$3) {
+         if ($1.toLowerCase() === 'group_concat') {
+           keywords.push('ALL');
+         } else {
+           keywords.push('ALL');
+           keywords.push('DISTINCT');
+         }
+       }
+       if (parser.yy.result.suggestKeywords) {
+         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       }
+       parser.suggestKeywords(keywords);
+     }
+     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
+       parser.applyArgumentTypesToSuggestions($1, $4.position);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+OtherAggregateFunction_Type
+ : 'APPX_MEDIAN'
+ | 'AVG'
+ | 'GROUP_CONCAT'
+ | 'STDDEV'
+ | 'STDDEV_POP'
+ | 'STDDEV_SAMP'
+ | 'MAX'
+ | 'MIN'
+ | 'NDV'
+ | 'VARIANCE'
+ | 'VARIANCE_POP'
+ | 'VARIANCE_SAMP'
+ | 'VAR_POP'
+ | 'VAR_SAMP'
+ ;
+
+ExtractFunction
+ : 'EXTRACT' '(' ValueExpression FromOrComma ValueExpression ')'
+ | 'EXTRACT' '(' ')'
+ ;
+
+ExtractFunction_EDIT
+ : 'EXTRACT' '(' AnyCursor FromOrComma ValueExpression RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' AnyCursor FromOrComma RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyTypeToSuggestions({ types: ['STRING', 'TIMESTAMP'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression_EDIT FromOrComma ValueExpression RightParenthesisOrError
+   {
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression_EDIT FromOrComma RightParenthesisOrError
+   {
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['STRING'] : ['TIMESTAMP'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression_EDIT RightParenthesisOrError
+   {
+     parser.applyTypeToSuggestions({ types: ['STRING', 'TIMESTAMP'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression FromOrComma AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' FromOrComma AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression FromOrComma ValueExpression_EDIT RightParenthesisOrError
+   {
+     parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' FromOrComma ValueExpression_EDIT RightParenthesisOrError
+   {
+    parser.applyTypeToSuggestions({ types: $4.toLowerCase() === 'from' ? ['TIMESTAMP'] : ['STRING'] });
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression 'CURSOR' ValueExpression RightParenthesisOrError
+   {
+     if ($3.types[0] === 'STRING') {
+       parser.suggestValueExpressionKeywords($3, ['FROM']);
+     } else {
+       parser.suggestValueExpressionKeywords($3);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'EXTRACT' '(' ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     if ($3.types[0] === 'STRING') {
+       parser.suggestValueExpressionKeywords($3, ['FROM']);
+     } else {
+       parser.suggestValueExpressionKeywords($3);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;
+
+FromOrComma
+ : 'FROM'
+ | ','
+ ;
+
+SumFunction
+ : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
+ | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
+ ;
+
+SumFunction_EDIT
+ : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
+   {
+     parser.valueExpressionSuggest();
+     parser.applyArgumentTypesToSuggestions($1, 1);
+     var keywords = parser.getSelectListKeywords(true);
+     if (!$3) {
+       keywords.push('DISTINCT');
+       keywords.push('ALL');
+     }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestValueExpressionKeywords($4);
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
+   {
+     if (parser.yy.result.suggestFunctions && ! parser.yy.result.suggestFunctions.types) {
+       parser.applyArgumentTypesToSuggestions($1, 1);
+     }
+     $$ = { function: $1, types: ['UDFREF'] };
+   }
+ ;

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/structure.json

@@ -13,6 +13,7 @@
     "sql_main.jison",
     "sql_set.jison",
     "sql_show.jison",
+    "sql_udf.jison",
     "sql_update.jison",
     "../generic/sql_use.jison",
     "sql_valueExpression.jison",
@@ -30,6 +31,7 @@
     "sql_main.jison",
     "sql_set.jison",
     "sql_show.jison",
+    "sql_udf.jison",
     "sql_update.jison",
     "../generic/sql_use.jison",
     "sql_valueExpression.jison",

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/ksql/structure.json

@@ -10,6 +10,7 @@
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
     "sql_show.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_valueExpression.jison",
     "../generic/autocomplete_footer.jison"
   ],
@@ -22,6 +23,7 @@
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
     "sql_show.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_valueExpression.jison",
     "../generic/syntax_footer.jison"
   ]

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/phoenix/structure.json

@@ -9,6 +9,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -22,6 +23,7 @@
     "../generic/sql_insert.jison",
     "../generic/sql_main.jison",
     "../generic/sql_set.jison",
+    "../generic/sql_udf.jison",
     "../generic/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

+ 2 - 452
desktop/core/src/desktop/js/parse/jison/sql/presto/sql_main.jison

@@ -2218,42 +2218,8 @@ InValueList
 
 NonParenthesizedValueExpressionPrimary
  : UnsignedValueSpecification
- | ColumnOrArbitraryFunctionRef             -> { types: ['COLREF'], columnReference: $1.chain }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart
-   {
-     // We need to handle arbitrary UDFs here instead of inside UserDefinedFunction or there will be a conflict
-     // with columnReference for functions like: db.udf(foo)
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.expression) {
-       $$ = { function: fn, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: fn, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-  {
-    parser.addFunctionLocation(@1, $1);
-    if ($2.expression) {
-      $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-    } else {
-      $$ = { function: $1, types: ['UDFREF'] }
-    }
-  }
- | UserDefinedFunction
- | 'NULL'                      -> { types: [ 'NULL' ] }
+ | ColumnOrArbitraryFunctionRef  -> { types: ['COLREF'], columnReference: $1.chain }
+ | 'NULL'                        -> { types: [ 'NULL' ] }
  ;
 
 NonParenthesizedValueExpressionPrimary_EDIT
@@ -2266,36 +2232,6 @@ NonParenthesizedValueExpressionPrimary_EDIT
        $$ = { types: ['COLREF'], columnReference: $1 };
      }
    }
- | ColumnOrArbitraryFunctionRef ArbitraryFunctionRightPart_EDIT
-   {
-     var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
-     }
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions(fn, $2.position);
-     }
-     $$ = { function: fn, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | UserDefinedFunction_EDIT
  ;
 
 ColumnOrArbitraryFunctionRef
@@ -2983,152 +2919,6 @@ OptionalLateralViews_EDIT
  : OptionalLateralViews LateralView_EDIT OptionalLateralViews
  ;
 
-UserDefinedFunction
- : AggregateFunction OptionalOverClause
-   {
-     if (!$2) {
-       $1.suggestKeywords = ['OVER'];
-     }
-   }
- | AnalyticFunction OverClause
- | CastFunction
- | ExtractFunction
- ;
-
-UserDefinedFunction_EDIT
- : AggregateFunction_EDIT
- | AggregateFunction OptionalOverClause_EDIT
- | AnalyticFunction_EDIT
- | AnalyticFunction_EDIT OverClause
- | AnalyticFunction 'CURSOR'
-   {
-     parser.suggestKeywords(['OVER']);
-   }
- | AnalyticFunction OverClause_EDIT
- | CastFunction_EDIT
- | ExtractFunction_EDIT
- ;
-
-ArbitraryFunction
- : RegularIdentifier ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.expression) {
-       $$ = { function: $1, expression: $2.expression, types: ['UDFREF'] }
-     } else {
-       $$ = { function: $1, types: ['UDFREF'] }
-     }
-   }
- ;
-
-ArbitraryFunction_EDIT
- : RegularIdentifier ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | ArbitraryFunctionName ArbitraryFunctionRightPart_EDIT
-   {
-     parser.addFunctionLocation(@1, $1);
-     if ($2.position) {
-       parser.applyArgumentTypesToSuggestions($1, $2.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ArbitraryFunctionName
- : 'ARRAY'
- | 'BINARY'
- | 'IF'
- | 'MAP'
- | 'TRUNCATE'
- ;
-
-ArbitraryFunctionRightPart
- : '(' ')'
- | '(' ValueExpressionList ')'  -> { expression: $2 }
- ;
-
-ArbitraryFunctionRightPart_EDIT
- : '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { position: 1 }
-   }
- | '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-   }
- | '(' ValueExpressionList_EDIT RightParenthesisOrError      -> $2
- ;
-
-AggregateFunction
- : CountFunction
- | SumFunction
- | OtherAggregateFunction
- ;
-
-AggregateFunction_EDIT
- : CountFunction_EDIT
- | SumFunction_EDIT
- | OtherAggregateFunction_EDIT
- ;
-
-AnalyticFunction
- : 'ANALYTIC' '(' ')'                      -> { function: $1, types: ['UDFREF'] }
- | 'ANALYTIC' '(' ValueExpressionList ')'  -> { function: $1, expression: $2, types: ['UDFREF'] }
- ;
-
-AnalyticFunction_EDIT
- : 'ANALYTIC' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'ANALYTIC' '(' ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     parser.applyArgumentTypesToSuggestions($1, $3.position);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OptionalOverClause
- :
- | OverClause
- ;
-
-OptionalOverClause_EDIT
- : OverClause_EDIT
- ;
-
-OverClause
- : 'OVER' RegularOrBacktickedIdentifier
- | 'OVER' WindowExpression
- ;
-
-OverClause_EDIT
- : 'OVER' WindowExpression_EDIT
- ;
-
 WindowExpression
  : '(' OptionalPartitionBy OptionalOrderByAndWindow ')'
  ;
@@ -3373,246 +3163,6 @@ WindowClause_EDIT
  | 'WINDOW' RegularOrBacktickedIdentifier 'AS' WindowExpression_EDIT
  ;
 
-CastFunction
- : 'CAST' '(' ValueExpression 'AS' PrimitiveType ')'  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ')'                                      -> { types: [ 'T' ] }
- ;
-
-CastFunction_EDIT
- : 'CAST' '(' AnyCursor 'AS' PrimitiveType RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' AnyCursor 'AS' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression_EDIT 'AS' PrimitiveType RightParenthesisOrError  -> { types: [ $5.toUpperCase() ] }
- | 'CAST' '(' ValueExpression_EDIT 'AS' RightParenthesisOrError                -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression_EDIT RightParenthesisOrError                      -> { types: [ 'T' ] }
- | 'CAST' '(' ValueExpression 'CURSOR' PrimitiveType RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ =  { types: [ $5.toUpperCase() ] };
-   }
- | 'CAST' '(' ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'AS', weight: 2 }]);
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' ValueExpression 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- | 'CAST' '(' 'AS' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(parser.getTypeKeywords());
-     $$ = { types: [ 'T' ] };
-   }
- ;
-
-CountFunction
- : 'COUNT' '(' '*' ')'                                        -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' ')'                                            -> { function: $1, types: ['UDFREF'] }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-CountFunction_EDIT
- : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords();
-     if (!$3) {
-       keywords.push('DISTINCT');
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords();
-       if (!$3) {
-         keywords.push('DISTINCT');
-       }
-       parser.suggestKeywords(keywords);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-ExtractFunction
- : 'EXTRACT' '(' DateField 'FROM' ValueExpression ')'  -> { types: ['INT', 'INTEGER'] }
- ;
-
-ExtractFunction_EDIT
- : 'EXTRACT' '(' AnyCursor RightParenthesisOrError
-   {
-     parser.suggestKeywords(['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR']);
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(['FROM']);
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'FROM' 'CURSOR' RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'FROM' ValueExpression_EDIT RightParenthesisOrError  -> { types: ['INT', 'INTEGER'] }
- | 'EXTRACT' '(' AnyCursor 'FROM' ValueExpression RightParenthesisOrError
-   {
-      parser.suggestKeywords(['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR']);
-      $$ = { types: ['INT', 'INTEGER'] }
-   }
- | 'EXTRACT' '(' DateField 'CURSOR' ValueExpression RightParenthesisOrError
-   {
-     parser.suggestKeywords(['FROM']);
-     $$ = { types: ['INT', 'INTEGER'] }
-   }
- ;
-
-DateField
- : 'DAY'
- | 'DAYOFWEEK'
- | 'HOUR'
- | 'MINUTE'
- | 'MONTH'
- | 'QUARTER'
- | 'SECOND'
- | 'WEEK'
- | 'YEAR'
- ;
-
-OtherAggregateFunction
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct ')'                      -> { function: $1, types: ['UDFREF'] }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList ')'  -> { function: $1, types: ['UDFREF'] }
- ;
-
-OtherAggregateFunction_EDIT
- : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       if ($1.toLowerCase() === 'group_concat') {
-         keywords.push('ALL');
-       } else {
-         keywords.push('DISTINCT');
-       }
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
-   {
-     if ($4.cursorAtStart) {
-       var keywords = parser.getSelectListKeywords(true);
-       if (!$3) {
-         if ($1.toLowerCase() === 'group_concat') {
-           keywords.push('ALL');
-         } else {
-           keywords.push('DISTINCT');
-         }
-       }
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
-       }
-       parser.suggestKeywords(keywords);
-     }
-     if (parser.yy.result.suggestFunctions && !parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, $4.position);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
-OtherAggregateFunction_Type
- : 'AVG'
- | 'COLLECT_LIST'
- | 'COLLECT_SET'
- | 'CORR'
- | 'COVAR_POP'
- | 'COVAR_SAMP'
- | 'HISTOGRAM_NUMERIC'
- | 'MAX'
- | 'MIN'
- | 'NTILE'
- | 'PERCENTILE'
- | 'PERCENTILE_APPROX'
- | 'STDDEV_POP'
- | 'STDDEV_SAMP'
- | 'VAR_POP'
- | 'VAR_SAMP'
- | 'VARIANCE'
- ;
-
-FromOrComma
- : 'FROM'
- | ','
- ;
-
-SumFunction
- : 'SUM' '(' OptionalAllOrDistinct ValueExpression ')'  -> { function: $1, types: ['UDFREF'] }
- | 'SUM' '(' ')'                                        -> { function: $1, types: ['UDFREF'] }
- ;
-
-SumFunction_EDIT
- : 'SUM' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
-   {
-     parser.valueExpressionSuggest();
-     parser.applyArgumentTypesToSuggestions($1, 1);
-     var keywords = parser.getSelectListKeywords(true);
-     if (!$3) {
-       keywords.push('DISTINCT');
-     }
-     if (parser.yy.result.suggestKeywords) {
-       keywords = parser.yy.result.suggestKeywords.concat(keywords);
-     }
-     parser.suggestKeywords(keywords);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestValueExpressionKeywords($4);
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- | 'SUM' '(' OptionalAllOrDistinct ValueExpression_EDIT RightParenthesisOrError
-   {
-     if (parser.yy.result.suggestFunctions && ! parser.yy.result.suggestFunctions.types) {
-       parser.applyArgumentTypesToSuggestions($1, 1);
-     }
-     $$ = { function: $1, types: ['UDFREF'] };
-   }
- ;
-
 LateralView
  : 'LATERAL' 'VIEW' OptionalOuter ArbitraryFunction RegularOrBacktickedIdentifier LateralViewColumnAliases  -> { lateralView: { udtf: $4, tableAlias: $5, columnAliases: $6 }}
  | 'LATERAL' 'VIEW' OptionalOuter ArbitraryFunction RegularOrBacktickedIdentifier

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/presto/structure.json

@@ -15,6 +15,7 @@
     "sql_msck.jison",
     "../hive/sql_set.jison",
     "../hive/show/sql_show.jison",
+    "../hive/sql_udf.jison",
     "../hive/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",
@@ -34,6 +35,7 @@
     "sql_msck.jison",
     "../hive/sql_set.jison",
     "../hive/show/sql_show.jison",
+    "../hive/sql_udf.jison",
     "../hive/sql_update.jison",
     "../generic/sql_use.jison",
     "../generic/sql_valueExpression.jison",

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/calcite/calciteAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/calcite/calciteSyntaxParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/druid/druidAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/druid/druidSyntaxParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchSyntaxParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/flink/flinkAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/flink/flinkSyntaxParser.js


+ 2 - 1
desktop/core/src/desktop/js/parse/sql/flink/sqlParseSupport.js

@@ -18,7 +18,8 @@ import { matchesType } from 'sql/reference/typeUtils';
 import stringDistance from 'sql/stringDistance';
 import {
   applyTypeToSuggestions,
-  getSubQuery, suggestKeywords,
+  getSubQuery,
+  suggestKeywords,
   valueExpressionSuggest
 } from 'parse/sql/sqlParseUtils';
 

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/generic/genericAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/generic/genericSyntaxParser.js


+ 2 - 1
desktop/core/src/desktop/js/parse/sql/generic/sqlParseSupport.js

@@ -18,7 +18,8 @@ import { matchesType } from 'sql/reference/typeUtils';
 import stringDistance from 'sql/stringDistance';
 import {
   applyTypeToSuggestions,
-  getSubQuery, suggestKeywords,
+  getSubQuery,
+  suggestKeywords,
   valueExpressionSuggest
 } from 'parse/sql/sqlParseUtils';
 

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/impala/impalaAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/impala/impalaSyntaxParser.js


+ 1 - 1
desktop/core/src/desktop/js/parse/sql/impala/sqlParseSupport.js

@@ -16,7 +16,7 @@
 
 import { matchesType } from 'sql/reference/typeUtils';
 import stringDistance from 'sql/stringDistance';
-import {applyTypeToSuggestions, getSubQuery, suggestKeywords} from 'parse/sql/sqlParseUtils';
+import { applyTypeToSuggestions, getSubQuery, suggestKeywords } from 'parse/sql/sqlParseUtils';
 
 const identifierEquals = (a, b) =>
   a &&

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/ksql/ksqlAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/ksql/ksqlSyntaxParser.js


+ 2 - 1
desktop/core/src/desktop/js/parse/sql/ksql/sqlParseSupport.js

@@ -18,7 +18,8 @@ import { matchesType } from 'sql/reference/typeUtils';
 import stringDistance from 'sql/stringDistance';
 import {
   applyTypeToSuggestions,
-  getSubQuery, suggestKeywords,
+  getSubQuery,
+  suggestKeywords,
   valueExpressionSuggest
 } from 'parse/sql/sqlParseUtils';
 

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/phoenix/phoenixAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/phoenix/phoenixSyntaxParser.js


+ 2 - 1
desktop/core/src/desktop/js/parse/sql/phoenix/sqlParseSupport.js

@@ -18,7 +18,8 @@ import { matchesType } from 'sql/reference/typeUtils';
 import stringDistance from 'sql/stringDistance';
 import {
   applyTypeToSuggestions,
-  getSubQuery, suggestKeywords,
+  getSubQuery,
+  suggestKeywords,
   valueExpressionSuggest
 } from 'parse/sql/sqlParseUtils';
 

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js


+ 1 - 1
desktop/core/src/desktop/js/parse/sql/presto/sqlParseSupport.js

@@ -15,7 +15,7 @@
 // limitations under the License.
 
 import { matchesType } from 'sql/reference/typeUtils';
-import {applyTypeToSuggestions, getSubQuery, suggestKeywords} from 'parse/sql/sqlParseUtils';
+import { applyTypeToSuggestions, getSubQuery, suggestKeywords } from 'parse/sql/sqlParseUtils';
 
 /**
  * Calculates the Optimal String Alignment distance between two strings. Returns 0 when the strings are equal and the

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików