mirror of https://github.com/apache/kafka.git
MINOR: Remove redundant casting and if condition from ConnectSchema (#9959)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
8bdab2e4cf
commit
fb6c7beb29
|
@ -44,31 +44,31 @@ public class ConnectSchema implements Schema {
|
|||
private static final Map<Class<?>, Type> JAVA_CLASS_SCHEMA_TYPES = new HashMap<>();
|
||||
|
||||
static {
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT8, Collections.singletonList((Class) Byte.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT16, Collections.singletonList((Class) Short.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT32, Collections.singletonList((Class) Integer.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT64, Collections.singletonList((Class) Long.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.FLOAT32, Collections.singletonList((Class) Float.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.FLOAT64, Collections.singletonList((Class) Double.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.BOOLEAN, Collections.singletonList((Class) Boolean.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.STRING, Collections.singletonList((Class) String.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT8, Collections.singletonList(Byte.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT16, Collections.singletonList(Short.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT32, Collections.singletonList(Integer.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.INT64, Collections.singletonList(Long.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.FLOAT32, Collections.singletonList(Float.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.FLOAT64, Collections.singletonList(Double.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.BOOLEAN, Collections.singletonList(Boolean.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.STRING, Collections.singletonList(String.class));
|
||||
// Bytes are special and have 2 representations. byte[] causes problems because it doesn't handle equals() and
|
||||
// hashCode() like we want objects to, so we support both byte[] and ByteBuffer. Using plain byte[] can cause
|
||||
// those methods to fail, so ByteBuffers are recommended
|
||||
SCHEMA_TYPE_CLASSES.put(Type.BYTES, Arrays.asList((Class) byte[].class, (Class) ByteBuffer.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.ARRAY, Collections.singletonList((Class) List.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.MAP, Collections.singletonList((Class) Map.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.STRUCT, Collections.singletonList((Class) Struct.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.BYTES, Arrays.asList(byte[].class, ByteBuffer.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.ARRAY, Collections.singletonList(List.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.MAP, Collections.singletonList(Map.class));
|
||||
SCHEMA_TYPE_CLASSES.put(Type.STRUCT, Collections.singletonList(Struct.class));
|
||||
|
||||
for (Map.Entry<Type, List<Class>> schemaClasses : SCHEMA_TYPE_CLASSES.entrySet()) {
|
||||
for (Class<?> schemaClass : schemaClasses.getValue())
|
||||
JAVA_CLASS_SCHEMA_TYPES.put(schemaClass, schemaClasses.getKey());
|
||||
}
|
||||
|
||||
LOGICAL_TYPE_CLASSES.put(Decimal.LOGICAL_NAME, Collections.singletonList((Class) BigDecimal.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Date.LOGICAL_NAME, Collections.singletonList((Class) java.util.Date.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Time.LOGICAL_NAME, Collections.singletonList((Class) java.util.Date.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Timestamp.LOGICAL_NAME, Collections.singletonList((Class) java.util.Date.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Decimal.LOGICAL_NAME, Collections.singletonList(BigDecimal.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Date.LOGICAL_NAME, Collections.singletonList(java.util.Date.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Time.LOGICAL_NAME, Collections.singletonList(java.util.Date.class));
|
||||
LOGICAL_TYPE_CLASSES.put(Timestamp.LOGICAL_NAME, Collections.singletonList(java.util.Date.class));
|
||||
// We don't need to put these into JAVA_CLASS_SCHEMA_TYPES since that's only used to determine schemas for
|
||||
// schemaless data and logical types will have ambiguous schemas (e.g. many of them use the same Java class) so
|
||||
// they should not be used without schemas.
|
||||
|
@ -110,7 +110,7 @@ public class ConnectSchema implements Schema {
|
|||
this.parameters = parameters;
|
||||
|
||||
if (this.type == Type.STRUCT) {
|
||||
this.fields = fields == null ? Collections.<Field>emptyList() : fields;
|
||||
this.fields = fields == null ? Collections.emptyList() : fields;
|
||||
this.fieldsByName = new HashMap<>(this.fields.size());
|
||||
for (Field field : this.fields)
|
||||
fieldsByName.put(field.name(), field);
|
||||
|
@ -229,14 +229,10 @@ public class ConnectSchema implements Schema {
|
|||
+ " for field: \"" + name + "\"");
|
||||
|
||||
boolean foundMatch = false;
|
||||
if (expectedClasses.size() == 1) {
|
||||
foundMatch = expectedClasses.get(0).isInstance(value);
|
||||
} else {
|
||||
for (Class<?> expectedClass : expectedClasses) {
|
||||
if (expectedClass.isInstance(value)) {
|
||||
foundMatch = true;
|
||||
break;
|
||||
}
|
||||
for (Class<?> expectedClass : expectedClasses) {
|
||||
if (expectedClass.isInstance(value)) {
|
||||
foundMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue