laskoviymishka commented on code in PR #16657:
URL: https://github.com/apache/iceberg/pull/16657#discussion_r3431896466
##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:
##########
@@ -300,28 +301,29 @@ protected List<Object> convertListValue(
Object value, ListType type, SchemaUpdate.Consumer schemaUpdateConsumer)
{
Preconditions.checkArgument(value instanceof List);
List<?> list = (List<?>) value;
- return list.stream()
- .map(
- element -> {
- int fieldId = type.fields().get(0).fieldId();
- return convertValue(element, type.elementType(), fieldId,
schemaUpdateConsumer);
- })
- .collect(Collectors.toList());
+ int elementFieldId = type.fields().get(0).fieldId();
+ Type elementType = type.elementType();
+ List<Object> result = Lists.newArrayListWithCapacity(list.size());
Review Comment:
While we're here — `TestRecordConverter` only ever runs these through
2-element lists/maps, so the new zero-capacity path
(`newArrayListWithCapacity(0)` / `newHashMapWithExpectedSize(0)`) isn't
exercised at all.
I'd add one test that converts a record with an empty list field and an
empty map field and asserts empty results. Cheap, and it closes a pre-existing
gap rather than just papering over this change.
##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:
##########
@@ -300,28 +301,29 @@ protected List<Object> convertListValue(
Object value, ListType type, SchemaUpdate.Consumer schemaUpdateConsumer)
{
Preconditions.checkArgument(value instanceof List);
List<?> list = (List<?>) value;
- return list.stream()
- .map(
- element -> {
- int fieldId = type.fields().get(0).fieldId();
- return convertValue(element, type.elementType(), fieldId,
schemaUpdateConsumer);
- })
- .collect(Collectors.toList());
+ int elementFieldId = type.fields().get(0).fieldId();
+ Type elementType = type.elementType();
+ List<Object> result = Lists.newArrayListWithCapacity(list.size());
+ for (Object element : list) {
+ result.add(convertValue(element, elementType, elementFieldId,
schemaUpdateConsumer));
+ }
+ return result;
}
protected Map<Object, Object> convertMapValue(
Object value, MapType type, SchemaUpdate.Consumer schemaUpdateConsumer) {
Preconditions.checkArgument(value instanceof Map);
Map<?, ?> map = (Map<?, ?>) value;
Review Comment:
Minor semantic shift: `get(1)` used to be evaluated lazily inside the
lambda, so an empty map never touched it — now it's eager at method entry.
`MapType` always has exactly two fields so there's no real regression, just
worth being aware of. No change needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]