joyhaldar commented on code in PR #15688:
URL: https://github.com/apache/iceberg/pull/15688#discussion_r2965005428
##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -140,6 +140,45 @@ void testDataWriterEngineWriteGenericRead(FileFormat
fileFormat, DataGenerator d
DataTestHelpers.assertEquals(schema.asStruct(), genericRecords,
readRecords);
}
+ @ParameterizedTest
+ @FieldSource("FORMAT_AND_GENERATOR")
+ /** Write with engine type T without explicit engineSchema, read with
Generic Record */
+ void testDataWriterEngineWriteWithoutEngineSchema(
+ FileFormat fileFormat, DataGenerator dataGenerator) throws IOException {
+ Schema schema = dataGenerator.schema();
+ FileWriterBuilder<DataWriter<T>, Object> writerBuilder =
+ FormatModelRegistry.dataWriteBuilder(fileFormat, engineType(),
encryptedFile);
+
+ DataWriter<T> writer =
writerBuilder.schema(schema).spec(PartitionSpec.unpartitioned()).build();
+
+ List<Record> genericRecords = dataGenerator.generateRecords();
+ List<T> engineRecords = convertToEngineRecords(genericRecords, schema);
+
+ try (writer) {
+ for (T record : engineRecords) {
+ writer.write(record);
+ }
+ }
+
+ DataFile dataFile = writer.toDataFile();
+
+ assertThat(dataFile).isNotNull();
+ assertThat(dataFile.recordCount()).isEqualTo(engineRecords.size());
+ assertThat(dataFile.format()).isEqualTo(fileFormat);
+
+ // Read back and verify
+ InputFile inputFile = encryptedFile.encryptingOutputFile().toInputFile();
+ List<Record> readRecords;
+ try (CloseableIterable<Record> reader =
+ FormatModelRegistry.readBuilder(fileFormat, Record.class, inputFile)
+ .project(schema)
+ .build()) {
+ readRecords = ImmutableList.copyOf(reader);
+ }
+
+ DataTestHelpers.assertEquals(schema.asStruct(), genericRecords,
readRecords);
Review Comment:
I have extracted `readAndAssertGenericRecords` helper. Inspired by
@Guosmilesmile's `writeGenericRecords` pattern in #15633.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]