Fix variable arguments bug in UDAF (#1523)

This commit is contained in:
WingC
2019-07-21 23:11:56 +08:00
committed by ZHAO Chun
parent 7b019ab37f
commit cd7ab5af0b
2 changed files with 12 additions and 6 deletions

View File

@ -150,8 +150,8 @@ public class CreateFunctionStmt extends DdlStmt {
private void analyzeUda() throws AnalysisException {
AggregateFunction.AggregateFunctionBuilder builder = AggregateFunction.AggregateFunctionBuilder.createUdfBuilder();
builder.name(functionName).argsType(argsDef.getArgTypes()).retType(returnType.getType())
.intermediateType(intermediateType.getType()).objectFile(objectFile);
builder.name(functionName).argsType(argsDef.getArgTypes()).retType(returnType.getType()).
hasVarArgs(argsDef.isVariadic()).intermediateType(intermediateType.getType()).objectFile(objectFile);
String initFnSymbol = properties.get(INIT_KEY);
if (initFnSymbol == null) {
throw new AnalysisException("No 'init_fn' in properties");

View File

@ -177,11 +177,11 @@ public class AggregateFunction extends Function {
// Used to create UDAF
public AggregateFunction(FunctionName fnName, Type[] argTypes,
Type retType, Type intermediateType, String location,
Type retType, boolean hasVarArgs, Type intermediateType, String location,
String initFnSymbol, String updateFnSymbol, String mergeFnSymbol,
String serializeFnSymbol, String finalizeFnSymbol,
String getValueFnSymbol, String removeFnSymbol) {
super(fnName, argTypes, retType, false);
super(fnName, argTypes, retType, hasVarArgs);
this.setLocation(new HdfsURI(location));
this.intermediateType = (intermediateType.equals(retType)) ? null : intermediateType;
this.updateFnSymbol = updateFnSymbol;
@ -202,6 +202,7 @@ public class AggregateFunction extends Function {
FunctionName name;
Type[] argTypes;
Type retType;
boolean hasVarArgs;
Type intermediateType;
String objectFile;
String initFnSymbol;
@ -235,6 +236,11 @@ public class AggregateFunction extends Function {
return this;
}
public AggregateFunctionBuilder hasVarArgs(boolean hasVarArgs) {
this.hasVarArgs = hasVarArgs;
return this;
}
public AggregateFunctionBuilder intermediateType(Type type) {
this.intermediateType = type;
return this;
@ -281,8 +287,8 @@ public class AggregateFunction extends Function {
}
public AggregateFunction build() {
AggregateFunction fn = new AggregateFunction(name, argTypes, retType, intermediateType, objectFile,
initFnSymbol, updateFnSymbol, mergeFnSymbol,
AggregateFunction fn = new AggregateFunction(name, argTypes, retType, hasVarArgs, intermediateType,
objectFile, initFnSymbol, updateFnSymbol, mergeFnSymbol,
serializeFnSymbol, finalizeFnSymbol,
getValueFnSymbol, removeFnSymbol);
fn.setBinaryType(binaryType);