nastra commented on code in PR #13933:
URL: https://github.com/apache/iceberg/pull/13933#discussion_r2349106368


##########
api/src/test/java/org/apache/iceberg/stats/TestStatsUtil.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.stats;
+
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.Types;
+import org.junit.jupiter.api.Test;
+
+public class TestStatsUtil {
+
+  @Test
+  public void statsIdsForTableColumns() {
+    int offset = 0;
+    // 10_000 + 200 * 7_084_950 = 1_417_000_000, which is the starting range 
for reserved columns
+    int max = (StatsUtil.METADATA_SPACE_FIELD_ID_START - 
StatsUtil.DATA_SPACE_FIELD_ID_START) / 200;
+    for (int id = 0; id < max; id++) {
+      int statsFieldId = StatsUtil.statsFieldIdFor(id);
+      int expected = StatsUtil.DATA_SPACE_FIELD_ID_START + offset;
+      assertThat(statsFieldId).as("at pos %s", id).isEqualTo(expected);
+      offset += StatsUtil.RESERVED_FIELD_IDS;
+      assertThat(StatsUtil.fieldIdFor(statsFieldId)).as("at pos %s", 
id).isEqualTo(id);
+    }
+  }
+
+  @Test
+  public void statsIdsOverflowForTableColumns() {
+    for (int i = 0; i < 100; i++) {
+      int id =
+          ThreadLocalRandom.current()

Review Comment:
   typically I try to avoid randomness in tests because it makes debugging more 
difficult. However, the table ID range here is large and the test takes very 
long to complete, thus I opted to use 100 random IDs from that table ID range



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