XieJiann commented on code in PR #23598: URL: https://github.com/apache/doris/pull/23598#discussion_r1316807505
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ArrayItemReference.java: ########## @@ -0,0 +1,150 @@ +// 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; + +import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes; +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.coercion.AnyDataType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; +import java.util.Objects; + +/** + * it is item from array, which used in lambda function + */ +public class ArrayItemReference extends NamedExpression implements ExpectsInputTypes { + protected final String name; + protected final ExprId exprId; + + /** ArrayItemReference */ + public ArrayItemReference(String name, Expression arrayExpression) { + this(StatementScopeIdGenerator.newExprId(), name, arrayExpression); + } + + public ArrayItemReference(ExprId exprId, String name, Expression arrayExpression) { + super(ImmutableList.of(arrayExpression)); + Preconditions.checkArgument(arrayExpression.getDataType() instanceof ArrayType, + "ArrayItemReference' child must return array"); + this.name = name; + this.exprId = exprId; + } + + public Expression getArrayExpression() { + return children.get(0); + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitArrayItemReference(this, context); + } + + @Override + public String getName() { + return name; + } + + @Override + public ExprId getExprId() { + return exprId; + } + + @Override + public List<String> getQualifier() { + return ImmutableList.of(name); + } + + @Override + public boolean nullable() { + return ((ArrayType) (this.children.get(0).getDataType())).containsNull(); + } + + @Override + public ArrayItemReference withChildren(List<Expression> expressions) { + return new ArrayItemReference(exprId, name, expressions.get(0)); + } + + @Override + public DataType getDataType() { + return ((ArrayType) (this.children.get(0).getDataType())).getItemType(); + } + + @Override + public String toSql() { + String str = getName() + "#" + getExprId(); + str += " of " + child(0).toSql(); + return str; Review Comment: done ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/ArrayItemReference.java: ########## @@ -0,0 +1,150 @@ +// 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; + +import org.apache.doris.nereids.trees.expressions.typecoercion.ExpectsInputTypes; +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.coercion.AnyDataType; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + +import java.util.List; +import java.util.Objects; + +/** + * it is item from array, which used in lambda function + */ +public class ArrayItemReference extends NamedExpression implements ExpectsInputTypes { + protected final String name; + protected final ExprId exprId; + + /** ArrayItemReference */ + public ArrayItemReference(String name, Expression arrayExpression) { + this(StatementScopeIdGenerator.newExprId(), name, arrayExpression); + } + + public ArrayItemReference(ExprId exprId, String name, Expression arrayExpression) { + super(ImmutableList.of(arrayExpression)); + Preconditions.checkArgument(arrayExpression.getDataType() instanceof ArrayType, + "ArrayItemReference' child must return array"); + this.name = name; + this.exprId = exprId; + } + + public Expression getArrayExpression() { + return children.get(0); + } + + @Override + public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) { + return visitor.visitArrayItemReference(this, context); + } + + @Override + public String getName() { + return name; + } + + @Override + public ExprId getExprId() { + return exprId; + } + + @Override + public List<String> getQualifier() { + return ImmutableList.of(name); + } + + @Override + public boolean nullable() { + return ((ArrayType) (this.children.get(0).getDataType())).containsNull(); + } + + @Override + public ArrayItemReference withChildren(List<Expression> expressions) { + return new ArrayItemReference(exprId, name, expressions.get(0)); + } + + @Override + public DataType getDataType() { + return ((ArrayType) (this.children.get(0).getDataType())).getItemType(); + } + + @Override + public String toSql() { + String str = getName() + "#" + getExprId(); + str += " of " + child(0).toSql(); + return str; + } + + @Override + public Slot toSlot() { + return new ArrayItemSlot(exprId, name, getDataType(), nullable()); + } + + @Override + public String toString() { + String str = getName() + "#" + getExprId(); + str += " of " + child(0).toString(); + return str; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ArrayItemReference that = (ArrayItemReference) o; + return Objects.equals(child(0), that.child(0)); + } + + @Override + public int hashCode() { + return Objects.hash(children, getExprId()); 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]
