Skip to content

Commit

Permalink
use datafiles builder
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanck committed Oct 21, 2023
1 parent 1b4f100 commit b5e9312
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@
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.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;
Expand All @@ -37,24 +45,13 @@ public class EventTestUtil {
private EventTestUtil() {}

public static DataFile createDataFile() {
Ctor<DataFile> ctor =
DynConstructors.builder(DataFile.class)
.hiddenImpl(
"org.apache.iceberg.GenericDataFile",
int.class,
String.class,
FileFormat.class,
PartitionData.class,
long.class,
Metrics.class,
ByteBuffer.class,
List.class,
int[].class,
Integer.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 @@ -63,17 +60,15 @@ public static DataFile createDataFile() {
Collections.emptyMap(),
Collections.emptyMap());

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

public static DeleteFile createDeleteFile() {
Expand Down

0 comments on commit b5e9312

Please sign in to comment.