Skip to content

Commit

Permalink
use builder instead of reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanck committed Oct 22, 2023
1 parent 5eff26b commit 2b376f2
Showing 1 changed file with 20 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,19 @@

import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.DataFiles;
import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.FileContent;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.FileMetadata;
import org.apache.iceberg.Metrics;
import org.apache.iceberg.NullOrder;
import org.apache.iceberg.PartitionData;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
import org.apache.iceberg.SortDirection;
import org.apache.iceberg.SortOrder;
import org.apache.iceberg.common.DynConstructors;
import org.apache.iceberg.common.DynConstructors.Ctor;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.types.Types.NestedField;
import org.apache.iceberg.types.Types.StringType;
import org.apache.iceberg.types.Types.StructType;

public class EventTestUtil {
private EventTestUtil() {}
Expand All @@ -48,7 +41,6 @@ public static DataFile createDataFile() {
Schema schema =
new Schema(ImmutableList.of(Types.NestedField.required(1, "id", Types.LongType.get())));
PartitionSpec spec = PartitionSpec.builderFor(schema).identity("id").withSpecId(1).build();

SortOrder order =
SortOrder.builderFor(schema).sortBy("id", SortDirection.ASC, NullOrder.NULLS_FIRST).build();

Expand All @@ -61,36 +53,23 @@ public static DataFile createDataFile() {
Collections.emptyMap());

return DataFiles.builder(spec)
.withPath("path")
.withFormat(FileFormat.PARQUET)
.withEncryptionKeyMetadata(ByteBuffer.wrap(new byte[] {0}))
.withFileSizeInBytes(1L)
.withFormat(FileFormat.PARQUET)
.withMetrics(metrics)
.withEncryptionKeyMetadata(ByteBuffer.wrap(new byte[] {0}))
.withSplitOffsets(ImmutableList.of(4L))
.withPath("path")
.withSortOrder(order)
.withSplitOffsets(ImmutableList.of(4L))
.build();
}

public static DeleteFile createDeleteFile() {
Ctor<DeleteFile> ctor =
DynConstructors.builder(DeleteFile.class)
.hiddenImpl(
"org.apache.iceberg.GenericDeleteFile",
int.class,
FileContent.class,
String.class,
FileFormat.class,
PartitionData.class,
long.class,
Metrics.class,
int[].class,
Integer.class,
List.class,
ByteBuffer.class)
.build();
Schema schema =
new Schema(ImmutableList.of(Types.NestedField.required(1, "id", Types.LongType.get())));
PartitionSpec spec = PartitionSpec.builderFor(schema).identity("id").withSpecId(1).build();
SortOrder order =
SortOrder.builderFor(schema).sortBy("id", SortDirection.ASC, NullOrder.NULLS_FIRST).build();

PartitionData partitionData =
new PartitionData(StructType.of(NestedField.required(999, "type", StringType.get())));
Metrics metrics =
new Metrics(
1L,
Expand All @@ -99,17 +78,15 @@ public static DeleteFile createDeleteFile() {
Collections.emptyMap(),
Collections.emptyMap());

return ctor.newInstance(
1,
FileContent.EQUALITY_DELETES,
"path",
FileFormat.PARQUET,
partitionData,
1L,
metrics,
new int[] {1},
1,
Collections.singletonList(1L),
ByteBuffer.wrap(new byte[] {0}));
return FileMetadata.deleteFileBuilder(spec)
.ofEqualityDeletes(1)
.withEncryptionKeyMetadata(ByteBuffer.wrap(new byte[] {0}))
.withFileSizeInBytes(1L)
.withFormat(FileFormat.PARQUET)
.withMetrics(metrics)
.withPath("path")
.withSortOrder(order)
.withSplitOffsets(ImmutableList.of(4L))
.build();
}
}

0 comments on commit 2b376f2

Please sign in to comment.