starocean999 commented on code in PR #58228:
URL: https://github.com/apache/doris/pull/58228#discussion_r2650061818
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -2692,6 +2693,58 @@ public LogicalPlan
visitTableValuedFunction(TableValuedFunctionContext ctx) {
});
}
+ @Override
+ public LogicalPlan visitUnnestFunction(DorisParser.UnnestFunctionContext
ctx) {
+ return withUnnest(ctx.unnest());
+ }
+
+ private LogicalPlan withUnnest(DorisParser.UnnestContext ctx) {
+ String defaultNestedColumnName = "unnest";
+ String defaultOrdinalityColumnName = "ordinality";
+ List<Expression> arguments = ctx.expression().stream()
+ .<Expression>map(this::typedVisit)
+ .collect(ImmutableList.toImmutableList());
+ boolean needOrdinality = ctx.ORDINALITY() != null;
+ int size = arguments.size();
+
+ String generateName = ctx.tableName != null ? ctx.tableName.getText()
: defaultNestedColumnName;
+ // do same thing as later view explode map type, we need to add a
project to convert map to struct
+ int argumentsSize = size + (needOrdinality ? 1 : 0);
+ List<String> nestedColumnNames = new ArrayList<>(argumentsSize);
+ int columnNamesSize = ctx.columnNames.size();
+ if (!ctx.columnNames.isEmpty()) {
+ for (int i = 0; i < columnNamesSize; ++i) {
+ nestedColumnNames.add(ctx.columnNames.get(i).getText());
+ }
+ for (int i = 0; i < size - columnNamesSize; ++i) {
+ nestedColumnNames.add(defaultNestedColumnName);
+ }
+ if (needOrdinality && columnNamesSize < argumentsSize) {
+ nestedColumnNames.add(defaultOrdinalityColumnName);
+ }
+ } else {
+ if (size == 1) {
+ nestedColumnNames.add(generateName);
+ } else {
+ for (int i = 0; i < size; ++i) {
+ nestedColumnNames.add(defaultNestedColumnName);
+ }
Review Comment:
yes, follow pg
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/generator/Unnest.java:
##########
@@ -0,0 +1,149 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.expressions.functions.generator;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
+import org.apache.doris.nereids.trees.expressions.functions.ComputePrecision;
+import org.apache.doris.nereids.trees.expressions.functions.CustomSignature;
+import org.apache.doris.nereids.trees.expressions.functions.SearchSignature;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.BitmapType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.MapType;
+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;
+
+/**
+ * unnest([1, 2, 3]), generate three rows include 1, 2 and 3.
+ * unnest([1, 2, 3], [4, 5, 6]) generates two columns and three rows
+ * where the first column contains 1, 2, 3, and the second column contains 4,
5, 6.
+ */
+public class Unnest extends TableGeneratingFunction implements
CustomSignature, ComputePrecision, AlwaysNullable {
+
+ private boolean isOuter;
+ private boolean needOrdinality;
+
+ /**
+ * constructor with one argument.
+ */
+ public Unnest(Expression argument) {
+ this(false, false, ImmutableList.of(argument));
+ }
+
+ /**
+ * constructor with more argument.
+ */
+ public Unnest(boolean isOuter, boolean needOrdinality, List<Expression>
arguments) {
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: [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]