Skip to content

Commit a55d494

Browse files
committed
chore: improve readability of type conversion logic
1 parent f9643e3 commit a55d494

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

core/src/main/java/kafka/automq/table/binder/AbstractTypeAdapter.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,40 @@ public Object convert(Object sourceValue, S sourceSchema, Type targetType) {
5454
return null;
5555
}
5656

57-
return switch (targetType.typeId()) {
58-
case BOOLEAN -> convertBoolean(sourceValue, sourceSchema, targetType);
59-
case INTEGER -> convertInteger(sourceValue, sourceSchema, targetType);
60-
case LONG -> convertLong(sourceValue, sourceSchema, targetType);
61-
case FLOAT -> convertFloat(sourceValue, sourceSchema, targetType);
62-
case DOUBLE -> convertDouble(sourceValue, sourceSchema, targetType);
63-
case STRING -> convertString(sourceValue, sourceSchema, targetType);
64-
case BINARY -> convertBinary(sourceValue, sourceSchema, targetType);
65-
case FIXED -> convertFixed(sourceValue, sourceSchema, targetType);
66-
case UUID -> convertUUID(sourceValue, sourceSchema, targetType);
67-
case DECIMAL -> convertDecimal(sourceValue, sourceSchema, (Types.DecimalType) targetType);
68-
case DATE -> convertDate(sourceValue, sourceSchema, targetType);
69-
case TIME -> convertTime(sourceValue, sourceSchema, targetType);
70-
case TIMESTAMP -> convertTimestamp(sourceValue, sourceSchema, (Types.TimestampType) targetType);
71-
case LIST -> convertList(sourceValue, sourceSchema, (Types.ListType) targetType);
72-
case MAP -> convertMap(sourceValue, sourceSchema, (Types.MapType) targetType);
73-
default -> sourceValue;
74-
};
57+
switch (targetType.typeId()) {
58+
case BOOLEAN:
59+
return convertBoolean(sourceValue, sourceSchema, targetType);
60+
case INTEGER:
61+
return convertInteger(sourceValue, sourceSchema, targetType);
62+
case LONG:
63+
return convertLong(sourceValue, sourceSchema, targetType);
64+
case FLOAT:
65+
return convertFloat(sourceValue, sourceSchema, targetType);
66+
case DOUBLE:
67+
return convertDouble(sourceValue, sourceSchema, targetType);
68+
case STRING:
69+
return convertString(sourceValue, sourceSchema, targetType);
70+
case BINARY:
71+
return convertBinary(sourceValue, sourceSchema, targetType);
72+
case FIXED:
73+
return convertFixed(sourceValue, sourceSchema, targetType);
74+
case UUID:
75+
return convertUUID(sourceValue, sourceSchema, targetType);
76+
case DECIMAL:
77+
return convertDecimal(sourceValue, sourceSchema, (Types.DecimalType) targetType);
78+
case DATE:
79+
return convertDate(sourceValue, sourceSchema, targetType);
80+
case TIME:
81+
return convertTime(sourceValue, sourceSchema, targetType);
82+
case TIMESTAMP:
83+
return convertTimestamp(sourceValue, sourceSchema, (Types.TimestampType) targetType);
84+
case LIST:
85+
return convertList(sourceValue, sourceSchema, (Types.ListType) targetType);
86+
case MAP:
87+
return convertMap(sourceValue, sourceSchema, (Types.MapType) targetType);
88+
default:
89+
return sourceValue;
90+
}
7591
}
7692

7793
protected Object convertBoolean(Object sourceValue, S ignoredSourceSchema, Type targetType) {

0 commit comments

Comments
 (0)