diff --git a/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java b/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java index d7220301c1ecaf..ad2457124d58b0 100644 --- a/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java +++ b/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java @@ -147,6 +147,7 @@ public BinaryPredicate() { public BinaryPredicate(Operator op, Expr e1, Expr e2) { super(); this.op = op; + this.opcode = op.opcode; Preconditions.checkNotNull(e1); children.add(e1); Preconditions.checkNotNull(e2); diff --git a/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java index 122c5e5d94e2f7..326d85de7eabdf 100644 --- a/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -437,6 +437,8 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException { } if (whereClause != null) { + // do this before whereClause.analyze , some expr is not analyzed, this may cause some + // function not work as expected such as equals; whereClauseRewrite(); if (checkGroupingFn(whereClause)) { throw new AnalysisException("grouping operations are not allowed in WHERE."); @@ -608,7 +610,7 @@ private Expr processDuplicateOrs(List> exprs) { if (clearExprs.size() == 1) { return makeCompound(clearExprs.get(0), CompoundPredicate.Operator.AND); } - // 2. find duplcate cross the clause + // 2. find duplicate cross the clause List cloneExprs = new ArrayList<>(clearExprs.get(0)); for (int i = 1; i < clearExprs.size(); ++i) { cloneExprs.retainAll(clearExprs.get(i)); diff --git a/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java b/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java index f2d1917d38f03f..769cba26583fb4 100644 --- a/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java +++ b/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java @@ -301,6 +301,12 @@ public void testDeduplicateOrs() throws Exception { stmt8.rewriteExprs(new Analyzer(ctx.getCatalog(), ctx).getExprRewriter()); Assert.assertTrue(stmt8.toSql().contains("((`t2`.`k1` IS NOT NULL) AND (`t1`.`k1` IS NOT NULL))" + " AND (`t1`.`k1` IS NOT NULL)")); + + String sql9 = "select * from db1.tbl1 where (k1='shutdown' and k4<1) or (k1='switchOff' and k4>=1)"; + SelectStmt stmt9 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql9, ctx); + stmt9.rewriteExprs(new Analyzer(ctx.getCatalog(), ctx).getExprRewriter()); + Assert.assertTrue(stmt9.toSql().contains("((`k1` = 'shutdown') AND (`k4` < 1))" + + " OR ((`k1` = 'switchOff') AND (`k4` >= 1))")); } @Test