linrrzqqq commented on code in PR #66968:
URL: https://github.com/apache/doris/pull/66968#discussion_r3865731665


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/MapLambdaFunctionUtils.java:
##########
@@ -0,0 +1,129 @@
+// 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.scalar;
+
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.ArrayItemReference;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.MapType;
+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.List;
+
+/** Utilities for building Map Lambda functions from one bound Map-entry array 
driver. */
+final class MapLambdaFunctionUtils {
+
+    private MapLambdaFunctionUtils() {
+    }
+
+    /** Build the function-specific body around a bound Map-entry Lambda. */
+    static RewrittenMapLambda rewrite(Lambda lambda, EntryBodyBuilder 
bodyBuilder) {
+        Expression mapExpression = extractMapExpression(lambda);
+        List<ArrayItemReference> arguments = lambda.getLambdaArguments();
+        ArrayItemReference entryArgument = arguments.get(0);
+        Slot entrySlot = entryArgument.toSlot();
+        Expression key = new ElementAt(entrySlot, new IntegerLiteral(1));
+        Expression value = new ElementAt(entrySlot, new IntegerLiteral(2));
+
+        Expression rewrittenBody = 
bodyBuilder.build(lambda.getLambdaFunction(), key, value, entrySlot);
+        Lambda rewrittenLambda = new Lambda(
+                ImmutableList.of(entryArgument.getName()), rewrittenBody, 
ImmutableList.of(entryArgument));
+        return new RewrittenMapLambda(mapExpression, rewrittenLambda);
+    }
+
+    /** Require a bound Lambda argument. */
+    static Lambda requireLambda(String functionName, Expression expression) {
+        if (!(expression instanceof Lambda)) {
+            throw new AnalysisException(String.format(
+                    "The 1st arg of %s must be lambda but is %s", 
functionName, expression));
+        }
+        return (Lambda) expression;
+    }
+
+    /** Fill only NULL_TYPE positions from the corresponding input Map field 
type. */
+    static DataType mergeNestedNullTypes(DataType outputType, DataType 
inputType) {

Review Comment:
   NullType 的行为不应该在 map lambda 里面自己处理,要么就是像 if 函数一样有返回类型的约束可以合并`if(cond, [], 
[1])`, 但是 map lambda 的参数形式显然不符合这种形式,报错感觉更合理些



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