[Feature](struct-type) Add implicitly cast for struct-type (#16613)

Currently not support insert {1, 'a'} into struct<f1:tinyint, f2:varchar(20)>
This commit will support implicitly cast the char type in the struct to varchar.
Add implicitly cast for struct-type.
This commit is contained in:
xy720
2023-02-15 16:55:00 +08:00
committed by GitHub
parent f50edff59d
commit 0c56a4622c
4 changed files with 100 additions and 4 deletions

View File

@ -123,8 +123,14 @@ public class StructField {
}
public static boolean canCastTo(StructField field, StructField targetField) {
// TODO(xy): support cast field
return false;
// not support cast not null to nullable
if (targetField.containsNull != field.containsNull) {
return false;
}
if (targetField.type.isStringType() && field.type.isStringType()) {
return true;
}
return Type.canCastTo(field.type, targetField.type);
}
public boolean matchesField(StructField f) {

View File

@ -85,8 +85,15 @@ public class StructType extends Type {
}
public static boolean canCastTo(StructType type, StructType targetType) {
// TODO(xy) : support cast struct type
return false;
if (type.fields.size() != targetType.fields.size()) {
return false;
}
for (int i = 0; i < type.fields.size(); i++) {
if (!StructField.canCastTo(type.fields.get(i), targetType.fields.get(i))) {
return false;
}
}
return true;
}
@Override