[opt](Nereids) let behavior of function char same with legacy planner (#34415)

1. first argument must be string like literal
2. only support utf-8 charset
This commit is contained in:
morrySnow
2024-05-06 16:14:52 +08:00
committed by yiguolei
parent 8fdfbcb3c4
commit 956ae2f83d
2 changed files with 16 additions and 10 deletions

View File

@ -18,9 +18,11 @@
package org.apache.doris.nereids.trees.expressions.functions.scalar;
import org.apache.doris.catalog.FunctionSignature;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.StringType;
@ -45,6 +47,18 @@ public class Char extends ScalarFunction
super("char", varArgs);
}
@Override
public void checkLegalityBeforeTypeCoercion() {
if (!(child(0) instanceof StringLikeLiteral)) {
throw new AnalysisException("char charset name must be a constant: " + child(0).toSql());
}
StringLikeLiteral stringLiteral = (StringLikeLiteral) child(0);
if (!"utf8".equalsIgnoreCase(stringLiteral.getStringValue())) {
throw new AnalysisException(
"char function currently only support charset name 'utf8': " + child(0).toSql());
}
}
/**
* withChildren.
*/