Guosmilesmile commented on code in PR #15906:
URL: https://github.com/apache/iceberg/pull/15906#discussion_r3091148775
##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -628,6 +639,326 @@ void
testReaderBuilderRecordsPerBatchNotSupported(FileFormat fileFormat) throws
.isInstanceOf(UnsupportedOperationException.class);
}
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testDataWriterMetricsCollection(FileFormat fileFormat) throws
IOException {
+ DataGenerator dataGenerator = new DataGenerators.DefaultSchema();
+ Schema schema = dataGenerator.schema();
+ FileWriterBuilder<DataWriter<Record>, Object> writerBuilder =
+ FormatModelRegistry.dataWriteBuilder(fileFormat, Record.class,
encryptedFile);
+
+ DataWriter<Record> writer =
+
writerBuilder.schema(schema).spec(PartitionSpec.unpartitioned()).build();
+
+ List<Record> genericRecords = dataGenerator.generateRecords();
+
+ try (writer) {
+ genericRecords.forEach(writer::write);
+ }
+
+ DataFile dataFile = writer.toDataFile();
+
+ assertThat(dataFile).isNotNull();
+ assertThat(dataFile.recordCount()).isEqualTo(genericRecords.size());
+
+ // AVRO Only support metric collection with rowCount
+ assumeSupports(fileFormat, FEATURE_METRIC_COLLECT);
+
+ assertValueAndNullCounts(
+ schema, genericRecords, dataFile.valueCounts(),
dataFile.nullValueCounts());
+ assertBounds(schema, genericRecords, dataFile.lowerBounds(),
dataFile.upperBounds());
+
+ assertThat(dataFile.columnSizes()).isNotNull().isNotEmpty();
+ }
+
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testDataWriterMetricsWithNoneMode(FileFormat fileFormat) throws
IOException {
+
+ // AVRO Only support metric collection with rowCount
+ assumeSupports(fileFormat, FEATURE_METRIC_COLLECT);
+
+ DataGenerator dataGenerator = new DataGenerators.DefaultSchema();
+ Schema schema = dataGenerator.schema();
+
+ TestTables.TestTable table =
+ TestTables.create(
+ tableDir,
+ "test",
+ schema,
+ PartitionSpec.unpartitioned(),
+ 3,
+ ImmutableMap.of(TableProperties.DEFAULT_WRITE_METRICS_MODE,
"none"));
+
+ MetricsConfig noneConfig = MetricsConfig.forTable(table);
+
+ FileWriterBuilder<DataWriter<Record>, Object> writerBuilder =
+ FormatModelRegistry.dataWriteBuilder(fileFormat, Record.class,
encryptedFile);
+
+ DataWriter<Record> writer =
+ writerBuilder
+ .schema(schema)
+ .spec(PartitionSpec.unpartitioned())
+ .metricsConfig(noneConfig)
+ .build();
+
+ List<Record> genericRecords = dataGenerator.generateRecords();
+
+ try (writer) {
+ genericRecords.forEach(writer::write);
+ }
+
+ DataFile dataFile = writer.toDataFile();
+
+ assertThat(dataFile).isNotNull();
+ assertThat(dataFile.recordCount()).isEqualTo(genericRecords.size());
+
+ // In `None` mode, `valueCounts`, `nullValueCounts`, `lowerBounds`, and
`upperBounds` should be
+ // empty/null.
Review Comment:
In Avro dataFile.valueCounts() return null , in others
dataFile.valueCounts() we can get a empty map.
--
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]