Improve allocations during Struct validation in ConnectSchema
Struct value validation in Kafka Connect can be optimized
to avoid creating an Iterator when the expectedClasses list is of
size 1. This is a meaningful enhancement for high throughput
connectors.
Reviewers: Konstantine Karantasis
@@ -229,12 +229,17 @@ 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;
}
}
+ }
+
if (!foundMatch)
throw new DataException("Invalid Java object for schema type " + schema.type()
+ ": " + value.getClass()
