rdblue commented on code in PR #17413:
URL: https://github.com/apache/iceberg/pull/17413#discussion_r3779790892
##########
core/src/test/java/org/apache/iceberg/StatsTestUtil.java:
##########
@@ -18,12 +18,80 @@
*/
package org.apache.iceberg;
+import java.util.List;
import org.apache.iceberg.types.Types;
import org.mockito.Mockito;
class StatsTestUtil {
+ private static final int FORMAT_VERSION_V4 = 4;
+
private StatsTestUtil() {}
+ static TrackedFile trackedFile(String location, long recordCount,
ContentStats stats) {
+ return new TrackedFileStruct(
+ null,
+ FileContent.DATA,
+ FORMAT_VERSION_V4,
+ location,
+ FileFormat.fromFileName(location),
+ recordCount,
+ 1024L,
+ 0,
+ null,
+ stats,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null);
+ }
+
+ static ContentStats contentStats(Types.StructType statsType,
FieldStats<?>... fieldStats) {
+ ContentStatsStruct stats = new ContentStatsStruct(statsType);
+ for (FieldStats<?> field : fieldStats) {
+ stats.setStats(field.fieldId(), field);
+ }
+
+ return stats;
+ }
+
+ /** Returns the stats for a field, where a null metric is one that the
column does not track. */
+ static FieldStats<Object> fieldStats(
+ Types.StructType statsType,
+ int fieldId,
+ Object lower,
+ Object upper,
+ Long valueCount,
+ Long nullCount,
+ Long nanCount) {
+ Types.StructType type =
statsType.field(StatsUtil.toBaseId(fieldId)).type().asStructType();
+ FieldStatsStruct<Object> stats = new FieldStatsStruct<>(type);
+ set(stats, StatsUtil.LOWER_BOUND_NAME, lower);
+ set(stats, StatsUtil.UPPER_BOUND_NAME, upper);
+ set(stats, "value_count", valueCount);
+ set(stats, "null_value_count", nullCount);
+ set(stats, "nan_value_count", nanCount);
Review Comment:
If you need to create test cases that aren't supported by the constructor,
use a mock or a test object (like the metrics tests do for data file) rather
than using set like this.
--
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]