HappenLee commented on code in PR #66734:
URL: https://github.com/apache/doris/pull/66734#discussion_r3777420086


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/generator/Stack.java:
##########
@@ -0,0 +1,146 @@
+// 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.exceptions.AnalysisException;
+import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE;
+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.literal.IntegerLikeLiteral;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.NullType;
+import org.apache.doris.nereids.types.StructField;
+import org.apache.doris.nereids.types.StructType;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * stack(n, expr1, ..., exprk) separates the expressions into n rows in 
row-major order.
+ * Missing values in the last row are padded with nulls.
+ */
+public class Stack extends TableGeneratingFunction implements CustomSignature, 
ComputePrecision, AlwaysNullable {
+
+    /** constructor with two or more arguments. */
+    public Stack(Expression numRows, Expression argument, Expression... 
otherArguments) {
+        super("stack", ExpressionUtils.mergeArguments(numRows, argument, 
otherArguments));
+    }
+
+    /** constructor for withChildren and reuse signature. */
+    private Stack(GeneratorFunctionParams functionParams) {
+        super(functionParams);
+    }
+
+    @Override
+    public Stack withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() >= 2);
+        return new Stack(getFunctionParams(children));
+    }
+
+    @Override
+    public void checkLegalityBeforeTypeCoercion() {
+        getColumnTypes();
+    }
+
+    @Override
+    public FunctionSignature computePrecision(FunctionSignature signature) {
+        return signature;
+    }
+
+    @Override
+    public FunctionSignature searchSignature(List<FunctionSignature> 
signatures) {
+        return super.searchSignature(signatures);
+    }
+
+    @Override
+    public FunctionSignature customSignature() {
+        List<DataType> columnTypes = getColumnTypes();
+        List<DataType> argumentTypes = new ArrayList<>(arity());
+        argumentTypes.add(IntegerType.INSTANCE);
+        for (int i = 1; i < arity(); i++) {
+            argumentTypes.add(columnTypes.get((i - 1) % columnTypes.size()));
+        }
+
+        if (columnTypes.size() == 1) {
+            return FunctionSignature.of(columnTypes.get(0), argumentTypes);
+        }
+        ImmutableList.Builder<StructField> fields = ImmutableList.builder();
+        for (int i = 0; i < columnTypes.size(); i++) {
+            fields.add(new StructField("col" + i, columnTypes.get(i), true, 
""));
+        }
+        return FunctionSignature.of(new StructType(fields.build()), 
argumentTypes);
+    }
+
+    private int getNumRows() {
+        Expression numRowsArgument = getArgument(0);
+        Expression evaluated = FoldConstantRuleOnFE.evaluate(numRowsArgument, 
null);

Review Comment:
   Fixed at 1fbb2a5f19f. Stack now uses an explicit context-free FE 
constant-folding entry point during schema derivation. Pure constant 
expressions such as arithmetic, CAST, and cardinality still fold recursively, 
while EncryptKeyRef and the other connection/session/catalog-dependent 
expressions remain unresolved and are rejected by Stack with its documented 
AnalysisException. This also covers the nested CAST(KEY test_db.test_key AS 
INT) path. Added analyzer regressions for both direct KEY and CAST(KEY ... AS 
INT). StackTest passes 10/10, and DISABLE_BUILD_UI=ON ./build.sh --fe -j 48 
passes.



-- 
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]

Reply via email to