morrySnow commented on code in PR #48537:
URL: https://github.com/apache/doris/pull/48537#discussion_r1998031718
##########
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.
*/
Review Comment:
change this comment
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/generator/ExplodeOuter.java:
##########
Review Comment:
same as Explode
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1694,7 +1694,13 @@ protected LogicalPlan withGenerate(LogicalPlan plan,
LateralViewContext ctx) {
// if later view explode map type, we need to add a project to convert
map to struct
String columnName = ctx.columnNames.get(0).getText();
List<String> expandColumnNames = Lists.newArrayList();
- if (ctx.columnNames.size() > 1) {
+
+ // explode can pass multiple columns
+ // then use struct to return the result of the expansion of multiple
columns.
+ String funcName = ctx.functionName.getText().toLowerCase();
+ if (ctx.columnNames.size() > 1 || (funcName.equals("explode")
+ || funcName.equals("explode_outer")
+ || funcName.equals("explode_variant_array"))) {
Review Comment:
add a function to
`org.apache.doris.catalog.BuiltinTableGeneratingFunctions`, this function
return a case insensitive list that include "explode", "explode_outer" and
"explode_variant_array"
##########
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:
should check NullLiteral's DataType and process it with three situations:
- ArrayType
- NullType
- other types
##########
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 {
Review Comment:
just like create named struct, we should impl `CumstomSignature` and
`ComputePrecision` @amorynan
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -1694,7 +1694,13 @@ protected LogicalPlan withGenerate(LogicalPlan plan,
LateralViewContext ctx) {
// if later view explode map type, we need to add a project to convert
map to struct
String columnName = ctx.columnNames.get(0).getText();
List<String> expandColumnNames = Lists.newArrayList();
Review Comment:
```suggestion
List<String> expandColumnNames = ImmutableList.of();
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]