From b4d413d3dbbd1d0a608657a39f40cec62bacc38a Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Tue, 3 Oct 2023 09:11:53 -0700 Subject: [PATCH] Revert "remove reflection" This reverts commit a849f4f829380bb6dc184e6cd2f4e9159fb7d795. --- .../org/apache/iceberg/GenericDataFile.java | 8 ++-- .../org/apache/iceberg/GenericDeleteFile.java | 8 ++-- .../connect/events/CommitResponsePayload.java | 14 ++++--- .../iceberg/connect/events/EventTestUtil.java | 42 +++++++++++++++++-- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/apache/iceberg/GenericDataFile.java b/core/src/main/java/org/apache/iceberg/GenericDataFile.java index cff3b7e2f268..07c5172f1b3f 100644 --- a/core/src/main/java/org/apache/iceberg/GenericDataFile.java +++ b/core/src/main/java/org/apache/iceberg/GenericDataFile.java @@ -25,13 +25,13 @@ import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.iceberg.types.Types; -public class GenericDataFile extends BaseFile implements DataFile { +class GenericDataFile extends BaseFile implements DataFile { /** Used by Avro reflection to instantiate this class when reading manifest files. */ - public GenericDataFile(Schema avroSchema) { + GenericDataFile(Schema avroSchema) { super(avroSchema); } - public GenericDataFile( + GenericDataFile( int specId, String filePath, FileFormat format, @@ -73,7 +73,7 @@ private GenericDataFile(GenericDataFile toCopy, boolean fullCopy) { } /** Constructor for Java serialization. */ - public GenericDataFile() {} + GenericDataFile() {} @Override public DataFile copyWithoutStats() { diff --git a/core/src/main/java/org/apache/iceberg/GenericDeleteFile.java b/core/src/main/java/org/apache/iceberg/GenericDeleteFile.java index bf92f028b3d8..cf20d931aa28 100644 --- a/core/src/main/java/org/apache/iceberg/GenericDeleteFile.java +++ b/core/src/main/java/org/apache/iceberg/GenericDeleteFile.java @@ -25,13 +25,13 @@ import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; import org.apache.iceberg.types.Types; -public class GenericDeleteFile extends BaseFile implements DeleteFile { +class GenericDeleteFile extends BaseFile implements DeleteFile { /** Used by Avro reflection to instantiate this class when reading manifest files. */ - public GenericDeleteFile(Schema avroSchema) { + GenericDeleteFile(Schema avroSchema) { super(avroSchema); } - public GenericDeleteFile( + GenericDeleteFile( int specId, FileContent content, String filePath, @@ -74,7 +74,7 @@ private GenericDeleteFile(GenericDeleteFile toCopy, boolean fullCopy) { } /** Constructor for Java serialization. */ - public GenericDeleteFile() {} + GenericDeleteFile() {} @Override public DeleteFile copyWithoutStats() { diff --git a/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/CommitResponsePayload.java b/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/CommitResponsePayload.java index 38ab01b81a17..59c131cc40ab 100644 --- a/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/CommitResponsePayload.java +++ b/kafka-connect/kafka-connect-events/src/main/java/org/apache/iceberg/connect/events/CommitResponsePayload.java @@ -24,8 +24,6 @@ import org.apache.avro.SchemaBuilder; import org.apache.iceberg.DataFile; import org.apache.iceberg.DeleteFile; -import org.apache.iceberg.GenericDataFile; -import org.apache.iceberg.GenericDeleteFile; import org.apache.iceberg.PartitionData; import org.apache.iceberg.avro.AvroSchemaUtil; import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; @@ -60,15 +58,19 @@ public CommitResponsePayload( AvroSchemaUtil.convert( dataFileStruct, ImmutableMap.of( - dataFileStruct, GenericDataFile.class.getName(), - partitionType, PartitionData.class.getName())); + dataFileStruct, + "org.apache.iceberg.GenericDataFile", + partitionType, + PartitionData.class.getName())); Schema deleteFileSchema = AvroSchemaUtil.convert( dataFileStruct, ImmutableMap.of( - dataFileStruct, GenericDeleteFile.class.getName(), - partitionType, PartitionData.class.getName())); + dataFileStruct, + "org.apache.iceberg.GenericDeleteFile", + partitionType, + PartitionData.class.getName())); this.avroSchema = SchemaBuilder.builder() 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 0b192657b62e..66ec70859015 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 @@ -20,20 +20,37 @@ import java.nio.ByteBuffer; import java.util.Collections; +import java.util.List; import org.apache.iceberg.DataFile; import org.apache.iceberg.DeleteFile; import org.apache.iceberg.FileContent; import org.apache.iceberg.FileFormat; -import org.apache.iceberg.GenericDataFile; -import org.apache.iceberg.GenericDeleteFile; import org.apache.iceberg.Metrics; import org.apache.iceberg.PartitionData; +import org.apache.iceberg.common.DynConstructors; +import org.apache.iceberg.common.DynConstructors.Ctor; import org.apache.iceberg.types.Types.NestedField; import org.apache.iceberg.types.Types.StringType; import org.apache.iceberg.types.Types.StructType; public class EventTestUtil { public static DataFile createDataFile() { + Ctor 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(); + PartitionData partitionData = new PartitionData(StructType.of(NestedField.required(999, "type", StringType.get()))); Metrics metrics = @@ -44,7 +61,7 @@ public static DataFile createDataFile() { Collections.emptyMap(), Collections.emptyMap()); - return new GenericDataFile( + return ctor.newInstance( 1, "path", FileFormat.PARQUET, @@ -58,6 +75,23 @@ public static DataFile createDataFile() { } public static DeleteFile createDeleteFile() { + Ctor 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(); + PartitionData partitionData = new PartitionData(StructType.of(NestedField.required(999, "type", StringType.get()))); Metrics metrics = @@ -68,7 +102,7 @@ public static DeleteFile createDeleteFile() { Collections.emptyMap(), Collections.emptyMap()); - return new GenericDeleteFile( + return ctor.newInstance( 1, FileContent.EQUALITY_DELETES, "path",