[fix](Nereids) Add varchar literal compare (#15672)

support "1" = "123"
This commit is contained in:
谢健
2023-01-11 02:41:50 +08:00
committed by GitHub
parent 280603b253
commit c87a9a5949
2 changed files with 10 additions and 1 deletions

View File

@ -139,7 +139,11 @@ public abstract class Literal extends Expression implements LeafExpression, Comp
DataType oType = other.getDataType();
DataType type = getDataType();
if (!type.equals(oType)) {
if (type.isVarcharType() && oType.isVarcharType()) {
// VarChar type can be different, e.g., VarChar(1) = VarChar(2)
return StringUtils.compare((String) getValue(), (String) other.getValue());
} else if (!type.equals(oType)) {
throw new RuntimeException("data type not equal!");
} else if (type.isBooleanType()) {
return Boolean.compare((boolean) getValue(), (boolean) other.getValue());

View File

@ -103,5 +103,10 @@ suite("nereids_function") {
sql "select convert_to('abc', cast(number as varchar)) from numbers('number'='1')"
exception "must be a constant"
}
test {
sql """select "1" == "123", "%%" == "%%" """
result([[false, true]])
}
}