[Fix](Planner) fix varchar does not show real length (#25171)
Problem: when we create table with datatype varchar(), we regard it to be max length by default. But when we desc, it does not show real length but show varchar() Reason: when we upgrade version from 2.0.1 to 2.0.2, we support new feature of creating varchar(), and it shows the same way with ddl schema. So user would confuse of the length of varchar Solved: change the showing of varchar() to varchar(65533), which in compatible with hive
This commit is contained in:
@ -367,6 +367,7 @@ import org.apache.doris.nereids.types.DataType;
|
||||
import org.apache.doris.nereids.types.MapType;
|
||||
import org.apache.doris.nereids.types.StructField;
|
||||
import org.apache.doris.nereids.types.StructType;
|
||||
import org.apache.doris.nereids.types.VarcharType;
|
||||
import org.apache.doris.nereids.types.coercion.CharacterType;
|
||||
import org.apache.doris.nereids.util.ExpressionUtils;
|
||||
import org.apache.doris.nereids.util.RelationUtil;
|
||||
@ -1655,6 +1656,9 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
|
||||
|
||||
private Expression processCast(Expression cast, DataType dataType) {
|
||||
if (dataType.isStringLikeType() && ((CharacterType) dataType).getLen() >= 0) {
|
||||
if (dataType.isVarcharType() && ((VarcharType) dataType).isWildcardVarchar()) {
|
||||
return cast;
|
||||
}
|
||||
List<Expression> args = ImmutableList.of(
|
||||
cast,
|
||||
new TinyIntLiteral((byte) 1),
|
||||
|
||||
@ -41,6 +41,7 @@ import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
|
||||
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
|
||||
import org.apache.doris.nereids.types.DataType;
|
||||
import org.apache.doris.nereids.types.VarcharType;
|
||||
import org.apache.doris.nereids.types.coercion.CharacterType;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -176,6 +177,9 @@ public class LogicalPlanTrinoBuilder extends io.trino.sql.tree.AstVisitor<Object
|
||||
DataType dataType = mappingType(node.getType());
|
||||
Expression cast = new Cast(expr, dataType);
|
||||
if (dataType.isStringLikeType() && ((CharacterType) dataType).getLen() >= 0) {
|
||||
if (dataType.isVarcharType() && ((VarcharType) dataType).isWildcardVarchar()) {
|
||||
return cast;
|
||||
}
|
||||
List<Expression> args = ImmutableList.of(
|
||||
cast,
|
||||
new TinyIntLiteral((byte) 1),
|
||||
|
||||
@ -67,7 +67,7 @@ public class VarcharType extends CharacterType {
|
||||
@Override
|
||||
public String toSql() {
|
||||
if (len == -1) {
|
||||
return "VARCHAR(*)";
|
||||
return "VARCHAR(" + MAX_VARCHAR_LENGTH + ")";
|
||||
}
|
||||
return "VARCHAR(" + len + ")";
|
||||
}
|
||||
@ -85,4 +85,8 @@ public class VarcharType extends CharacterType {
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), len);
|
||||
}
|
||||
|
||||
public boolean isWildcardVarchar() {
|
||||
return len == -1 || len == MAX_VARCHAR_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user