Skip to content

Commit

Permalink
[fix](planner)fix 'char' function's toSql implementation is wrong (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 authored and xiaokang committed Sep 6, 2023
1 parent ab228fd commit b767749
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ private String paramsToSql() {
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")
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/view_p0/view_p0.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
-- !sql --
960

-- !sql2 --


9 changes: 8 additions & 1 deletion regression-test/suites/view_p0/view_p0.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
}

0 comments on commit b767749

Please sign in to comment.