taptao commented on code in PR #48537: URL: https://github.com/apache/doris/pull/48537#discussion_r2002435849
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/generator/Explode.java: ########## @@ -18,47 +18,71 @@ package org.apache.doris.nereids.trees.expressions.functions.generator; import org.apache.doris.catalog.FunctionSignature; +import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable; -import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; +import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; -import org.apache.doris.nereids.types.coercion.AnyDataType; -import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; +import org.apache.doris.nereids.types.DataType; +import org.apache.doris.nereids.types.NullType; +import org.apache.doris.nereids.types.StructField; +import org.apache.doris.nereids.types.StructType; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import java.util.ArrayList; import java.util.List; /** * explode([1, 2, 3]), generate 3 lines include 1, 2 and 3. */ -public class Explode extends TableGeneratingFunction implements BinaryExpression, AlwaysNullable { - - public static final List<FunctionSignature> SIGNATURES = ImmutableList.of( - FunctionSignature.ret(new FollowToAnyDataType(0)).args(ArrayType.of(new AnyDataType(0))) - ); +public class Explode extends TableGeneratingFunction implements ExplicitlyCastableSignature, AlwaysNullable { /** - * constructor with 1 argument. + * constructor with one or more argument. */ - public Explode(Expression arg) { - super("explode", arg); + public Explode(Expression[] args) { + super("explode", args); } /** * withChildren. */ @Override public Explode withChildren(List<Expression> children) { - Preconditions.checkArgument(children.size() == 1); - return new Explode(children.get(0)); + Preconditions.checkArgument(!children.isEmpty()); + return new Explode(children.toArray(new Expression[0])); + } + + @Override + public void checkLegalityBeforeTypeCoercion() { + for (Expression child : children) { + if (!child.isNullLiteral() && !(child.getDataType() instanceof ArrayType)) { + throw new AnalysisException("only support array type for explode function but got " + + child.getDataType()); + } + } } @Override public List<FunctionSignature> getSignatures() { - return SIGNATURES; + List<DataType> arguments = new ArrayList<>(); + ImmutableList.Builder<StructField> structFields = ImmutableList.builder(); + for (int i = 0; i < children.size(); i++) { + if (children.get(i).isNullLiteral()) { + arguments.add(ArrayType.of(NullType.INSTANCE)); + structFields.add( + new StructField("col" + (i + 1), ArrayType.of(NullType.INSTANCE).getItemType(), true, "")); Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org