From f33aa77634ea42364b67f292c12f4f46d365b927 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Mon, 6 Nov 2023 08:11:34 -0800 Subject: [PATCH] position check and test update --- .../apache/iceberg/connect/events/AvroUtil.java | 3 ++- .../iceberg/connect/events/EventTestUtil.java | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/AvroUtil.java b/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/AvroUtil.java index 8e40c37f3230..8f184c21b401 100644 --- a/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/AvroUtil.java +++ b/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/AvroUtil.java @@ -85,7 +85,8 @@ static Schema convert( static int positionToId(int position, Schema avroSchema) { List fields = avroSchema.getFields(); - Preconditions.checkArgument(position < fields.size(), "Invalid field position: " + position); + Preconditions.checkArgument( + position >= 0 && position < fields.size(), "Invalid field position: " + position); Object val = fields.get(position).getObjectProp(AvroSchemaUtil.FIELD_ID_PROP); return val == null ? -1 : (int) val; } diff --git a/kafka-connect/kafka-connect-events/src/test/java/org/apache/iceberg/connect/events/EventTestUtil.java b/kafka-connect/kafka-connect-events/src/test/java/org/apache/iceberg/connect/events/EventTestUtil.java index 52c1204f8ad8..8f1f7a601f86 100644 --- a/kafka-connect/kafka-connect-events/src/test/java/org/apache/iceberg/connect/events/EventTestUtil.java +++ b/kafka-connect/kafka-connect-events/src/test/java/org/apache/iceberg/connect/events/EventTestUtil.java @@ -22,7 +22,6 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; -import java.util.Collections; import org.apache.iceberg.DataFile; import org.apache.iceberg.DataFiles; import org.apache.iceberg.DeleteFile; @@ -36,6 +35,7 @@ import org.apache.iceberg.SortDirection; import org.apache.iceberg.SortOrder; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.iceberg.types.Types; class EventTestUtil { @@ -53,10 +53,12 @@ private EventTestUtil() {} static final Metrics METRICS = new Metrics( 1L, - Collections.emptyMap(), - Collections.emptyMap(), - Collections.emptyMap(), - Collections.emptyMap()); + ImmutableMap.of(1, 1L), + ImmutableMap.of(1, 1L), + ImmutableMap.of(1, 1L), + ImmutableMap.of(1, 1L), + ImmutableMap.of(1, ByteBuffer.wrap(new byte[10])), + ImmutableMap.of(1, ByteBuffer.wrap(new byte[10]))); static OffsetDateTime now() { return OffsetDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.MICROS); @@ -72,7 +74,7 @@ static DataFile createDataFile() { .withFormat(FileFormat.PARQUET) .withMetrics(METRICS) .withPartition(data) - .withPath("path") + .withPath("path/to/file.parquet") .withSortOrder(ORDER) .withSplitOffsets(ImmutableList.of(4L)) .build(); @@ -89,7 +91,7 @@ static DeleteFile createDeleteFile() { .withFormat(FileFormat.PARQUET) .withMetrics(METRICS) .withPartition(data) - .withPath("path") + .withPath("path/to/file.parquet") .withSortOrder(ORDER) .withSplitOffsets(ImmutableList.of(4L)) .build();