morrySnow commented on code in PR #10672: URL: https://github.com/apache/doris/pull/10672#discussion_r916542491
########## fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java: ########## @@ -89,51 +87,36 @@ public static Expression or(List<Expression> expressions) { * Use AND/OR to combine expressions together. */ public static Expression combine(NodeType op, List<Expression> expressions) { - Objects.requireNonNull(expressions, "expressions is null"); if (expressions.size() == 0) { - if (op == NodeType.AND) { - return new Literal(true); - } - if (op == NodeType.OR) { - return new Literal(false); - } - } - - if (expressions.size() == 1) { + return new Literal(op == NodeType.AND); + } else if (expressions.size() == 1) { return expressions.get(0); } - List<Expression> distinctExpressions = Lists.newArrayList(new LinkedHashSet<>(expressions)); - if (op == NodeType.AND) { - if (distinctExpressions.contains(Literal.FALSE_LITERAL)) { - return Literal.FALSE_LITERAL; + Expression shortCircuit = (op == NodeType.AND ? Literal.FALSE_LITERAL : Literal.TRUE_LITERAL); + Expression skip = (op == NodeType.AND ? Literal.TRUE_LITERAL : Literal.FALSE_LITERAL); + LinkedHashSet<Expression> distinctExpressions = Sets.newLinkedHashSetWithExpectedSize(expressions.size()); + for (Expression expression : expressions) { + if (expression.equals(shortCircuit)) { + return shortCircuit; + } else if (!expression.equals(skip)) { + distinctExpressions.add(expression); } - distinctExpressions = distinctExpressions.stream().filter(p -> !p.equals(Literal.TRUE_LITERAL)) - .collect(Collectors.toList()); } - if (op == NodeType.OR) { - if (distinctExpressions.contains(Literal.TRUE_LITERAL)) { - return Literal.TRUE_LITERAL; + List<Expression> result = Lists.newArrayListWithCapacity(distinctExpressions.size() / 2 + 1); Review Comment: maybe we could use stream reduce api to do this without recursion ########## fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java: ########## @@ -28,10 +28,7 @@ public class Utils { * @return quoted string */ public static String quoteIfNeeded(String part) { - if (part.matches("[a-zA-Z0-9_]+") && !part.matches("\\d+")) { - return part; - } else { - return part.replace("`", "``"); - } + return part.matches("\\w*[\\w&&[^\\d]]+\\w*") Review Comment: this pattern is not intuitional. it is better add a comment to explain the pattern means all legal string except pure digit string. ########## fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java: ########## @@ -89,51 +87,36 @@ public static Expression or(List<Expression> expressions) { * Use AND/OR to combine expressions together. */ public static Expression combine(NodeType op, List<Expression> expressions) { - Objects.requireNonNull(expressions, "expressions is null"); if (expressions.size() == 0) { - if (op == NodeType.AND) { - return new Literal(true); - } - if (op == NodeType.OR) { - return new Literal(false); - } - } - - if (expressions.size() == 1) { + return new Literal(op == NodeType.AND); Review Comment: If u do that, u need add a check at the top of this function to check `NodeType` is either `AND` or `OR` -- 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