morrySnow commented on code in PR #10377: URL: https://github.com/apache/doris/pull/10377#discussion_r905908998
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java: ########## @@ -0,0 +1,70 @@ +// 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.exceptions.UnboundException; +import org.apache.doris.nereids.trees.NodeType; +import org.apache.doris.nereids.types.BooleanType; +import org.apache.doris.nereids.types.DataType; + +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; + +/** + * In Predicate Expression. + */ +public class InPredicate extends Expression { + private Expression compareExpression; + private List<Expression> inExpressions; + + public InPredicate(Expression compareExpression, List<Expression> inExpressions) { + super(NodeType.IN, + (new Builder<Expression>().add(compareExpression).addAll(inExpressions) + .build().toArray(new Expression[0]))); + this.compareExpression = compareExpression; + this.inExpressions = ImmutableList.copyOf(Objects.requireNonNull(inExpressions, "in list can not be null")); + } + + @Override + public DataType getDataType() throws UnboundException { + return BooleanType.INSTANCE; + } + + @Override + public String sql() { + return compareExpression.sql() + " IN (" + inExpressions.stream() Review Comment: ```suggestion return compareExpression.sql() + " IN " + inExpressions.stream() ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java: ########## @@ -537,9 +540,15 @@ public Expression visitPredicated(PredicatedContext ctx) { * @return Expression */ public Expression withPredicate(PredicateContext ctx, Expression e) { + boolean isNot = ctx.NOT() != null ? true : false; + Expression outExpression; switch (ctx.kind.getType()) { case DorisParser.BETWEEN: - return withBetween(ctx, e); + outExpression = withBetween(ctx, e); + return isNot ? new Not(outExpression) : outExpression; + case DorisParser.IN: + outExpression = withIn(ctx, e); + return isNot ? new Not(outExpression) : outExpression; default: return null; Review Comment: throw parse exception here, so we can do `return isNot ? new Not(outExpression) : outExpression;` at the end ########## fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/ExpressionParserTest.java: ########## @@ -25,18 +25,18 @@ public class ExpressionParserTest { private static final SqlParser PARSER = new SqlParser(); - private void assertSql(String sql) throws Exception { + private void assertSql(String sql) { TreeNode treeNode = PARSER.parse(sql); - System.out.println(treeNode.toString()); + assert treeNode != null; Review Comment: if you want to assert, it is better to use junit functions ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Not.java: ########## @@ -64,7 +64,7 @@ public boolean equals(Object o) { } @Override - public String toString() { - return "( not " + child() + ")"; + public String sql() { + return "( not " + child().sql() + ")"; Review Comment: ```suggestion return "( NOT " + child().sql() + ")"; ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java: ########## @@ -537,11 +541,17 @@ public Expression visitPredicated(PredicatedContext ctx) { * @return Expression */ public Expression withPredicate(PredicateContext ctx, Expression e) { + boolean isNot = ctx.NOT() != null ? true : false; + Expression outExpression; switch (ctx.kind.getType()) { case DorisParser.BETWEEN: - return withBetween(ctx, e); + outExpression = withBetween(ctx, e); + return isNot ? new Not(outExpression) : outExpression; + case DorisParser.IN: + outExpression = withIn(ctx, e); + return isNot ? new Not(outExpression) : outExpression; Review Comment: we can move this statement to the end of this function and do not need process in each case -- 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