Skip to content

Commit

Permalink
fix fold constant
Browse files Browse the repository at this point in the history
  • Loading branch information
keanji-x committed Nov 2, 2023
1 parent 6010be8 commit 695cd07
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ public static BinaryPredicate read(DataInput in) throws IOException {
}

@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
final Expr leftChildValue = getChild(0);
final Expr rightChildValue = getChild(1);
if (!(leftChildValue instanceof LiteralExpr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ public boolean canHashPartition() {
}

@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
final Expr value = children.get(0);
if (!(value instanceof LiteralExpr)) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public static boolean isOr(Expr expr) {
}

@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
boolean compoundResult = false;
if (op == Operator.NOT) {
final Expr childValue = getChild(0);
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2189,10 +2189,10 @@ public boolean supportSerializable() {
}


protected void recursiveResetChildrenResult(boolean inView) throws AnalysisException {
protected void recursiveResetChildrenResult(boolean forPushDownPredicatesToView) throws AnalysisException {
for (int i = 0; i < children.size(); i++) {
final Expr child = children.get(i);
final Expr newChild = child.getResultValue(inView);
final Expr newChild = child.getResultValue(forPushDownPredicatesToView);
if (newChild != child) {
setChild(i, newChild);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public String toString() {
}

@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
final Expr leftChildValue = getChild(0);
if (!(leftChildValue instanceof LiteralExpr) || !isLiteralChildren()) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ public boolean isNullable() {
* fix issue 6390
*/
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
// Don't push down predicate to view for is null predicate because the value can contain null
// after outer join
recursiveResetChildrenResult(!forPushDownPredicatesToView);
final Expr childValue = getChild(0);
if (!(childValue instanceof LiteralExpr)) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ public boolean matchExprs(List<Expr> exprs, SelectStmt stmt, boolean ignoreAlias
}

@Override
public Expr getResultValue(boolean foldSlot) throws AnalysisException {
if (!foldSlot) {
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
if (!forPushDownPredicatesToView) {
return this;
}
if (!isConstant() || desc == null) {
Expand All @@ -626,7 +626,7 @@ public Expr getResultValue(boolean foldSlot) throws AnalysisException {
}
Expr expr = exprs.get(0);
if (expr instanceof SlotRef) {
return expr.getResultValue(foldSlot);
return expr.getResultValue(forPushDownPredicatesToView);
}
if (expr.isConstant()) {
return expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Expr getLiteralExpr() {
}

@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
if (!Strings.isNullOrEmpty(name) && VariableVarConverters.hasConverter(name)) {
// Return the string type here so that it can correctly match the subsequent function signature.
// And we also set `beConverted` to session variable name in StringLiteral, so that it can be cast back
Expand Down
5 changes: 5 additions & 0 deletions regression-test/data/query_p0/literal_view/lietral_test.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --

-- !left --
3 flink 20 \N
1 doris 10 \N
2 spark 2 \N

-- !sql1 --

11 changes: 10 additions & 1 deletion regression-test/suites/query_p0/literal_view/lietral_test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ suite("literal_view_test") {
insert into test_insert values (1,'doris',10),(2,'spark',2),(3,'flink',20);
"""

qt_sql1 """
sql "set enable_nereids_planner=false"
order_qt_left """select *
from test_insert
left join (select 1 as v1) t1
on false
where t1.v1 is null
"""
sql "set enable_nereids_planner=true"

order_qt_sql1 """
select id, name
from (
select '123' as id,
Expand Down

0 comments on commit 695cd07

Please sign in to comment.