ajantha-bhat commented on code in PR #12226:
URL: https://github.com/apache/iceberg/pull/12226#discussion_r2002425079


##########
core/src/test/java/org/apache/iceberg/TestPartitionStats.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestPartitionStats {
+
+  private static final PartitionData PARTITION =
+      new PartitionData(
+          Types.StructType.of(Types.NestedField.required(1, "foo", 
Types.IntegerType.get())));
+
+  @Test
+  public void testAppendWithAllValues() {
+    PartitionStats stats1 =
+        createStats(100L, 15, 1000L, 2L, 500, 1L, 200, 15L, 1625077800000L, 
12345L);
+    PartitionStats stats2 = createStats(200L, 7, 500L, 1L, 100, 0L, 50, 7L, 
1625077900000L, 12346L);
+
+    stats1.appendStats(stats2);
+
+    validateStats(stats1, 300L, 22, 1500L, 3L, 600, 1L, 250, 22L, 
1625077900000L, 12346L);
+  }
+
+  @Test
+  public void testAppendWithThisNullOptionalField() {
+    PartitionStats stats1 = createStats(100L, 15, 1000L, 2L, 500, 1L, 200, 
null, null, null);
+    PartitionStats stats2 = createStats(100L, 7, 500L, 1L, 100, 0L, 50, 7L, 
1625077900000L, 12346L);
+
+    stats1.appendStats(stats2);
+
+    validateStats(stats1, 200L, 22, 1500L, 3L, 600, 1L, 250, 7L, 
1625077900000L, 12346L);
+  }
+
+  @Test
+  public void testAppendWithBothNullOptionalFields() {
+    PartitionStats stats1 = createStats(100L, 15, 1000L, 2L, 500, 1L, 200, 
null, null, null);
+    PartitionStats stats2 = createStats(100L, 7, 500L, 1L, 100, 0L, 50, null, 
null, null);
+
+    stats1.appendStats(stats2);
+
+    validateStats(stats1, 200L, 22, 1500L, 3L, 600, 1L, 250, null, null, null);
+  }
+
+  @Test
+  public void testAppendWithOtherNullOptionalFields() {
+    PartitionStats stats1 =
+        createStats(100L, 15, 1000L, 2L, 500, 1L, 200, 15L, 1625077900000L, 
12346L);
+    PartitionStats stats2 = createStats(100L, 7, 500L, 1L, 100, 0L, 50, null, 
null, null);
+
+    stats1.appendStats(stats2);
+
+    validateStats(stats1, 200L, 22, 1500L, 3L, 600, 1L, 250, 15L, 
1625077900000L, 12346L);
+  }
+
+  @Test
+  public void testAppendWithDifferentSpec() {
+    PartitionStats stats1 = new PartitionStats(PARTITION, 1);
+    PartitionStats stats2 = new PartitionStats(PARTITION, 2);
+
+    assertThatThrownBy(() -> stats1.appendStats(stats2))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Spec IDs must match");
+  }
+
+  private PartitionStats createStats(
+      long dataRecordCount,
+      int dataFileCount,
+      long totalDataFileSizeInBytes,
+      long positionDeleteRecordCount,
+      int positionDeleteFileCount,
+      long equalityDeleteRecordCount,
+      int equalityDeleteFileCount,
+      Long totalRecordCount,
+      Long lastUpdatedAt,
+      Long lastUpdatedSnapshotId) {
+
+    PartitionStats stats = new PartitionStats(PARTITION, 1);

Review Comment:
   Added
   
   
https://github.com/apache/iceberg/compare/e6c50140f8f915778c8cd120f81a40d643f72c2e..e4a60331b04ed2eabfe09b763387bdf67ff7021f



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to