[fix](Nereids) alias function support arithmetic functions (#25162)
This commit is contained in:
@ -699,7 +699,7 @@ public class BindExpression implements AnalysisRuleFactory {
|
||||
String functionName = unboundTVFRelation.getFunctionName();
|
||||
Properties arguments = unboundTVFRelation.getProperties();
|
||||
FunctionBuilder functionBuilder = functionRegistry.findFunctionBuilder(functionName, arguments);
|
||||
BoundFunction function = functionBuilder.build(functionName, arguments);
|
||||
Expression function = functionBuilder.build(functionName, arguments);
|
||||
if (!(function instanceof TableValuedFunction)) {
|
||||
throw new AnalysisException(function.toSql() + " is not a TableValuedFunction");
|
||||
}
|
||||
@ -727,12 +727,11 @@ public class BindExpression implements AnalysisRuleFactory {
|
||||
|
||||
String functionName = unboundFunction.getName();
|
||||
FunctionBuilder functionBuilder = functionRegistry.findFunctionBuilder(functionName, boundArguments);
|
||||
BoundFunction function = functionBuilder.build(functionName, boundArguments);
|
||||
Expression function = functionBuilder.build(functionName, boundArguments);
|
||||
if (!(function instanceof TableGeneratingFunction)) {
|
||||
throw new AnalysisException(function.toSql() + " is not a TableGeneratingFunction");
|
||||
}
|
||||
function = (BoundFunction) TypeCoercionUtils.processBoundFunction(function);
|
||||
return function;
|
||||
return (BoundFunction) TypeCoercionUtils.processBoundFunction((BoundFunction) function);
|
||||
}
|
||||
|
||||
private void checkIfOutputAliasNameDuplicatedForGroupBy(List<Expression> expressions,
|
||||
|
||||
@ -158,14 +158,13 @@ public class FunctionBinder extends AbstractExpressionRewriteRule {
|
||||
.accept(this, context);
|
||||
}
|
||||
|
||||
FunctionBuilder builder = functionRegistry.findFunctionBuilder(unboundFunction.getDbName(),
|
||||
functionName, arguments);
|
||||
BoundFunction boundFunction = builder.build(functionName, arguments);
|
||||
FunctionBuilder builder = functionRegistry.findFunctionBuilder(
|
||||
unboundFunction.getDbName(), functionName, arguments);
|
||||
if (builder instanceof AliasUdfBuilder) {
|
||||
// we do type coercion in build function in alias function, so it's ok to return directly.
|
||||
return boundFunction;
|
||||
return builder.build(functionName, arguments);
|
||||
} else {
|
||||
return TypeCoercionUtils.processBoundFunction(boundFunction);
|
||||
return TypeCoercionUtils.processBoundFunction((BoundFunction) builder.build(functionName, arguments));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,8 @@
|
||||
|
||||
package org.apache.doris.nereids.trees.expressions.functions;
|
||||
|
||||
import org.apache.doris.nereids.trees.expressions.Expression;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.List;
|
||||
@ -28,7 +30,7 @@ public abstract class FunctionBuilder {
|
||||
/** check whether arguments can apply to the constructor */
|
||||
public abstract boolean canApply(List<? extends Object> arguments);
|
||||
|
||||
public final BoundFunction build(String name, Object argument) {
|
||||
public final Expression build(String name, Object argument) {
|
||||
return build(name, ImmutableList.of(argument));
|
||||
}
|
||||
|
||||
@ -38,5 +40,5 @@ public abstract class FunctionBuilder {
|
||||
* @param arguments the function's argument expressions
|
||||
* @return the concrete bound function instance
|
||||
*/
|
||||
public abstract BoundFunction build(String name, List<? extends Object> arguments);
|
||||
public abstract Expression build(String name, List<? extends Object> arguments);
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class AliasUdfBuilder extends UdfBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoundFunction build(String name, List<?> arguments) {
|
||||
public Expression build(String name, List<?> arguments) {
|
||||
// use AliasFunction to process TypeCoercion
|
||||
BoundFunction boundAliasFunction = ((BoundFunction) aliasUdf.withChildren(arguments.stream()
|
||||
.map(Expression.class::cast).collect(Collectors.toList())));
|
||||
@ -90,7 +90,7 @@ public class AliasUdfBuilder extends UdfBuilder {
|
||||
replaceMap.put(slots.get(parameter), inputs.get(i));
|
||||
}
|
||||
|
||||
return ((BoundFunction) SlotReplacer.INSTANCE.replace(boundFunction, replaceMap));
|
||||
return SlotReplacer.INSTANCE.replace(boundFunction, replaceMap);
|
||||
}
|
||||
|
||||
private static class SlotReplacer extends DefaultExpressionRewriter<Map<SlotReference, Expression>> {
|
||||
|
||||
Reference in New Issue
Block a user