Skip to content

Commit

Permalink
[fix](Nereids) fix fold constant by be return type mismatched (#39723)
Browse files Browse the repository at this point in the history
when using fold constant by be, the return type of substring('123456',
1, 3) would changed to be text, which we want it to be 3
  • Loading branch information
LiBinfeng-01 committed Oct 8, 2024
1 parent 21718c5 commit 6dcdb03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ private Expression replace(Expression root, Map<String, Expression> constMap, Ma
if (newChild != child) {
hasNewChildren = true;
}
newChildren.add(newChild);
if (!newChild.getDataType().equals(child.getDataType())) {
try {
newChildren.add(newChild.castTo(child.getDataType()));
} catch (Exception e) {
LOG.warn("expression of type {} cast to {} failed. ", newChild.getDataType(), child.getDataType());
newChildren.add(newChild);
}
} else {
newChildren.add(newChild);
}
}
return hasNewChildren ? root.withChildren(newChildren) : root;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ suite("fold_constant_by_be") {
sql """ INSERT INTO str_tb VALUES (2, repeat("test1111", 10000)); """

qt_sql_1 """ select length(v1) from str_tb; """
}

explain {
sql("verbose select substring('123456', 1, 3)")
contains "varchar(3)"
}
}

0 comments on commit 6dcdb03

Please sign in to comment.