@@ -102,7 +102,7 @@ public class AggregateFunction extends Function {
102102 // empty input in BE).
103103 private boolean returnsNonNullOnEmpty ;
104104
105- //use for java-udaf to point the class of user define
105+ // use for java-udaf to point the class of user define
106106 private String symbolName ;
107107
108108 // only used for serialization
@@ -154,28 +154,28 @@ public static AggregateFunction createBuiltin(String name,
154154 }
155155
156156 public AggregateFunction (FunctionName fnName , List <Type > argTypes ,
157- Type retType , Type intermediateType ,
158- URI location , String updateFnSymbol , String initFnSymbol ,
159- String serializeFnSymbol , String mergeFnSymbol , String getValueFnSymbol ,
160- String removeFnSymbol , String finalizeFnSymbol , boolean vectorized ) {
157+ Type retType , Type intermediateType ,
158+ URI location , String updateFnSymbol , String initFnSymbol ,
159+ String serializeFnSymbol , String mergeFnSymbol , String getValueFnSymbol ,
160+ String removeFnSymbol , String finalizeFnSymbol , boolean vectorized ) {
161161 this (fnName , argTypes , retType , intermediateType , false , location ,
162162 updateFnSymbol , initFnSymbol , serializeFnSymbol ,
163163 mergeFnSymbol , getValueFnSymbol , removeFnSymbol , finalizeFnSymbol , vectorized );
164164 }
165165
166166 public AggregateFunction (FunctionName fnName , List <Type > argTypes ,
167- Type retType , Type intermediateType , boolean hasVarArgs ,
168- URI location , String updateFnSymbol , String initFnSymbol ,
169- String serializeFnSymbol , String mergeFnSymbol , String getValueFnSymbol ,
170- String removeFnSymbol , String finalizeFnSymbol , boolean vectorized ) {
167+ Type retType , Type intermediateType , boolean hasVarArgs ,
168+ URI location , String updateFnSymbol , String initFnSymbol ,
169+ String serializeFnSymbol , String mergeFnSymbol , String getValueFnSymbol ,
170+ String removeFnSymbol , String finalizeFnSymbol , boolean vectorized ) {
171171 // only `count` is always not nullable, other aggregate function is always nullable
172172 super (fnName , argTypes , retType , hasVarArgs , vectorized ,
173173 AggregateFunction .NOT_NULLABLE_AGGREGATE_FUNCTION_NAME_SET .contains (fnName .getFunction ())
174174 ? NullableMode .ALWAYS_NOT_NULLABLE :
175- AggregateFunction .ALWAYS_NULLABLE_AGGREGATE_FUNCTION_NAME_SET .contains (fnName .getFunction ())
176- ? NullableMode .ALWAYS_NULLABLE :
177- AggregateFunction .CUSTOM_AGGREGATE_FUNCTION_NAME_SET .contains (fnName .getFunction ())
178- ? NullableMode .CUSTOM : NullableMode .DEPEND_ON_ARGUMENT );
175+ AggregateFunction .ALWAYS_NULLABLE_AGGREGATE_FUNCTION_NAME_SET .contains (fnName .getFunction ())
176+ ? NullableMode .ALWAYS_NULLABLE :
177+ AggregateFunction .CUSTOM_AGGREGATE_FUNCTION_NAME_SET .contains (fnName .getFunction ())
178+ ? NullableMode .CUSTOM : NullableMode .DEPEND_ON_ARGUMENT );
179179 setLocation (location );
180180 this .intermediateType = (intermediateType .equals (retType )) ? null : intermediateType ;
181181 this .updateFnSymbol = updateFnSymbol ;
@@ -330,10 +330,10 @@ public static AggregateFunction createAnalyticBuiltin(String name,
330330
331331 // Used to create UDAF
332332 public AggregateFunction (FunctionName fnName , Type [] argTypes ,
333- Type retType , boolean hasVarArgs , Type intermediateType , URI location ,
334- String initFnSymbol , String updateFnSymbol , String mergeFnSymbol ,
335- String serializeFnSymbol , String finalizeFnSymbol ,
336- String getValueFnSymbol , String removeFnSymbol ) {
333+ Type retType , boolean hasVarArgs , Type intermediateType , URI location ,
334+ String initFnSymbol , String updateFnSymbol , String mergeFnSymbol ,
335+ String serializeFnSymbol , String finalizeFnSymbol ,
336+ String getValueFnSymbol , String removeFnSymbol ) {
337337 super (fnName , Arrays .asList (argTypes ), retType , hasVarArgs );
338338 this .setLocation (location );
339339 this .intermediateType = (intermediateType .equals (retType )) ? null : intermediateType ;
@@ -558,8 +558,14 @@ public void setIntermediateType(Type t) {
558558 }
559559
560560 @ Override
561- public String toSql (boolean ifNotExists ) {
562- StringBuilder sb = new StringBuilder ("CREATE AGGREGATE FUNCTION " );
561+ public String toSql (boolean ifNotExists , boolean isGlobal ) {
562+ StringBuilder sb = new StringBuilder ("CREATE " );
563+
564+ if (isGlobal ) {
565+ sb .append ("GLOBAL " );
566+ }
567+ sb .append ("AGGREGATE FUNCTION " );
568+
563569 if (ifNotExists ) {
564570 sb .append ("IF NOT EXISTS " );
565571 }
@@ -610,13 +616,13 @@ public TFunction toThrift(Type realReturnType, Type[] realArgTypes) {
610616 aggFn .setSerializeFnSymbol (serializeFnSymbol );
611617 }
612618 aggFn .setMergeFnSymbol (mergeFnSymbol );
613- if (getValueFnSymbol != null ) {
619+ if (getValueFnSymbol != null ) {
614620 aggFn .setGetValueFnSymbol (getValueFnSymbol );
615621 }
616- if (removeFnSymbol != null ) {
622+ if (removeFnSymbol != null ) {
617623 aggFn .setRemoveFnSymbol (removeFnSymbol );
618624 }
619- if (finalizeFnSymbol != null ) {
625+ if (finalizeFnSymbol != null ) {
620626 aggFn .setFinalizeFnSymbol (finalizeFnSymbol );
621627 }
622628 if (symbolName != null ) {
@@ -691,7 +697,7 @@ public String getProperties() {
691697 properties .put (CreateFunctionStmt .SERIALIZE_KEY , serializeFnSymbol );
692698 properties .put (CreateFunctionStmt .FINALIZE_KEY , finalizeFnSymbol );
693699
694- //getValueFn and removeFn may be null if not analytic agg
700+ // getValueFn and removeFn may be null if not analytic agg
695701 if (getValueFnSymbol != null ) {
696702 properties .put (CreateFunctionStmt .GET_VALUE_KEY , getValueFnSymbol );
697703 }
0 commit comments