pvary commented on code in PR #15906:
URL: https://github.com/apache/iceberg/pull/15906#discussion_r3099863804


##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -628,6 +644,239 @@ 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();
+
+    List<Record> genericRecords = dataGenerator.generateRecords();
+    DataFile dataFile = writeGenericRecords(fileFormat, schema, 
genericRecords);
+
+    assertThat(dataFile).isNotNull();
+    assertThat(dataFile.recordCount()).isEqualTo(genericRecords.size());
+
+    assertValueAndNullCounts(
+        fileFormat, schema, genericRecords, dataFile.valueCounts(), 
dataFile.nullValueCounts());
+    assertBounds(
+        fileFormat, schema, genericRecords, dataFile.lowerBounds(), 
dataFile.upperBounds());
+
+    assertThat(dataFile.columnSizes()).isNotNull().isNotEmpty();
+  }
+
+  @ParameterizedTest
+  @FieldSource("FILE_FORMATS")
+  void testDataWriterMetricsWithNoneMode(FileFormat fileFormat) throws 
IOException {
+    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);
+    List<Record> genericRecords = dataGenerator.generateRecords();
+    DataFile dataFile = writeGenericRecords(fileFormat, schema, 
genericRecords, noneConfig);
+
+    assertThat(dataFile).isNotNull();
+    assertThat(dataFile.recordCount()).isEqualTo(genericRecords.size());
+
+    assertCountsNull(fileFormat, schema, dataFile.valueCounts(), 
dataFile.nullValueCounts());
+    assertBoundsNull(fileFormat, schema, dataFile.lowerBounds(), 
dataFile.upperBounds());
+  }
+
+  @ParameterizedTest
+  @FieldSource("FILE_FORMATS")
+  void testDataWriterMetricsWithCountsMode(FileFormat fileFormat) throws 
IOException {
+    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, 
"counts"));
+
+    MetricsConfig countsConfig = MetricsConfig.forTable(table);
+
+    List<Record> genericRecords = dataGenerator.generateRecords();
+    DataFile dataFile = writeGenericRecords(fileFormat, schema, 
genericRecords, countsConfig);
+
+    assertThat(dataFile).isNotNull();
+    assertThat(dataFile.recordCount()).isEqualTo(genericRecords.size());
+
+    // In the counts mode, valueCounts and nullValueCounts should be present, 
while lowerBounds and
+    // upperBounds should be null.
+    assertValueAndNullCounts(
+        fileFormat, schema, genericRecords, dataFile.valueCounts(), 
dataFile.nullValueCounts());
+    assertBoundsNull(fileFormat, schema, dataFile.lowerBounds(), 
dataFile.upperBounds());
+  }
+
+  @ParameterizedTest
+  @FieldSource("FILE_FORMATS")
+  void testEqualityDeleteWriterMetricsCollection(FileFormat fileFormat) throws 
IOException {
+    DataGenerator dataGenerator = new DataGenerators.DefaultSchema();
+    Schema schema = dataGenerator.schema();
+    FileWriterBuilder<EqualityDeleteWriter<Record>, Object> writerBuilder =
+        FormatModelRegistry.equalityDeleteWriteBuilder(fileFormat, 
Record.class, encryptedFile);
+
+    EqualityDeleteWriter<Record> writer =

Review Comment:
   MetricsConfig could be a parameter, or we can create a method for 
`MetricsConfig countsConfig = metricsConfig("counts")`



-- 
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]

Reply via email to