[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:
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user