Skip to content

Commit

Permalink
position check and test update
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanck committed Jan 4, 2024
1 parent 224fc3c commit f33aa77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ static Schema convert(

static int positionToId(int position, Schema avroSchema) {
List<Schema.Field> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit f33aa77

Please sign in to comment.