XieJiann commented on code in PR #23598:
URL: https://github.com/apache/doris/pull/23598#discussion_r1316787662


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Lambda.java:
##########
@@ -0,0 +1,162 @@
+// 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.trees.expressions.ArrayItemReference;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.ArrayType;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.LambdaType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * Lambda includes lambda arguments and function body
+ * Before bind, x -> x : arguments("x") -> children: Expression(x)
+ * After bind, x -> x : arguments("x") -> children: Expression(x) 
ArrayItemReference(x)
+ */
+public class Lambda extends Expression {
+    final List<String> argumentNames;
+
+    /**
+     * constructor
+     */
+    public Lambda(List<String> argumentNames, Expression lambdaFunction) {
+        super(lambdaFunction);
+        this.argumentNames = argumentNames;
+    }
+
+    public Lambda(List<String> argumentNames, Expression lambdaFunction, 
List<ArrayItemReference> arguments) {
+        
super(ImmutableList.<Expression>builder().add(lambdaFunction).addAll(arguments).build());
+        this.argumentNames = argumentNames;
+    }
+
+    public Lambda(List<String> argumentNames, List<Expression> children) {
+        super(children);
+        this.argumentNames = argumentNames;
+    }
+
+    /**
+     * make slot according array expression
+     * @param arrays array expression
+     * @return item slots of array expression
+     */
+    public ImmutableList<ArrayItemReference> makeArguments(List<Expression> 
arrays) {
+        Builder<ArrayItemReference> builder = new ImmutableList.Builder<>();
+        for (int i = 0; i < arrays.size(); i++) {
+            Expression array = arrays.get(i);
+            String name = argumentNames.get(i);
+            Preconditions.checkArgument(array.getDataType() instanceof 
ArrayType, "lambda must receive array");
+            builder.add(new ArrayItemReference(name, array));
+        }
+        return builder.build();
+    }
+
+    public String getLambdaArgumentName(int i) {
+        return argumentNames.get(i);
+    }
+
+    public ArrayItemReference getLambdaArgument(int i) {
+        return (ArrayItemReference) children.get(i + 1);
+    }
+
+    public List<ArrayItemReference> getLambdaArguments() {
+        return children.stream()
+                .skip(1)
+                .map(e -> (ArrayItemReference) e)
+                .collect(Collectors.toList());
+    }
+
+    public List<String> getLambdaArgumentNames() {
+        return argumentNames;
+    }
+
+    public Expression getLambdaFunction() {
+        return child(0);
+    }
+
+    @Override
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitLambda(this, context);
+    }
+
+    public Lambda withLambdaFunctionArguments(Expression lambdaFunction, 
List<ArrayItemReference> arguments) {
+        return new Lambda(argumentNames, lambdaFunction, arguments);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        Lambda that = (Lambda) o;
+        return argumentNames.equals(that.argumentNames)
+                && Objects.equals(children(), that.children());
+    }
+
+    @Override
+    public String toSql() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(String.format("%s -> %s", argumentNames,

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

Reply via email to