[fix](planner)fix 'char' function's toSql implementation is wrong (#23860)

This commit is contained in:
starocean999
2023-09-06 16:16:16 +08:00
committed by GitHub
parent df1f4f843a
commit cb9acf4918
3 changed files with 31 additions and 1 deletions

View File

@ -551,6 +551,26 @@ public class FunctionCallExpr extends Expr {
sb.append("DISTINCT ");
}
int len = children.size();
if (fnName.getFunction().equalsIgnoreCase("char")) {
for (int i = 1; i < len; ++i) {
sb.append(children.get(i).toSql());
if (i < len - 1) {
sb.append(", ");
}
}
sb.append(" using ");
String encodeType = children.get(0).toSql();
if (encodeType.charAt(0) == '\'') {
encodeType = encodeType.substring(1, encodeType.length());
}
if (encodeType.charAt(encodeType.length() - 1) == '\'') {
encodeType = encodeType.substring(0, encodeType.length() - 1);
}
sb.append(encodeType).append(")");
return sb.toString();
}
// XXX_diff are used by nereids only
if (fnName.getFunction().equalsIgnoreCase("years_diff") || fnName.getFunction().equalsIgnoreCase("months_diff")
|| fnName.getFunction().equalsIgnoreCase("days_diff")

View File

@ -15,3 +15,6 @@
-- !sql --
960
-- !sql2 --

View File

@ -122,5 +122,12 @@ suite("view_p0") {
qt_sql "select * from test_time_diff"
sql "drop view if exists test_time_diff"
sql "drop view if exists test_vv1;"
sql "create view test_vv1 as select char(field2) from test_array_tbl_2;"
qt_sql2 "select * from test_vv1;"
sql "drop view if exists test_vv1;"
}