[Fix](Nereids) fix append_trailing_char_if_absent function return null (#41157)

cherry-pick: https://github.com/apache/doris/pull/40820
example: select append_trailing_char_if_absent('it','a') would return
null in original design, it can not return null when folding constant on
fe any time
This commit is contained in:
LiBinfeng
2024-09-26 16:18:12 +08:00
committed by GitHub
parent 43c1066bc7
commit f422b82e24
3 changed files with 110 additions and 4 deletions

View File

@ -105,13 +105,19 @@ public class ExecutableFunctions {
}
}
/**
* append_trailing_char_if_absent function
*/
@ExecFunction(name = "append_trailing_char_if_absent", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR")
public static Expression appendTrailingIfCharAbsent(StringLikeLiteral literal, StringLikeLiteral chr) {
if (literal.getValue().length() != 1) {
return null;
if (chr.getValue().length() != 1) {
return new NullLiteral(literal.getDataType());
}
if (literal.getValue().endsWith(chr.getValue())) {
return literal;
} else {
return new VarcharLiteral(literal.getValue() + chr.getValue());
}
return literal.getValue().endsWith(chr.getValue()) ? literal
: new VarcharLiteral(literal.getValue() + chr.getValue());
}
@ExecFunction(name = "e", argTypes = {}, returnType = "DOUBLE")