Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,13 @@ private static long generateContentLength() {
}

private static Pair<ByteBuffer, ByteBuffer> generateBounds(PrimitiveType type, MetricsMode mode) {
Comparator<Object> cmp = Comparators.forType(type);
Object value1 = generateBound(type, mode);
Object value2 = generateBound(type, mode);

if (value1 == null || value2 == null) {
return Pair.of(null, null);
}
Comparator<Object> cmp = Comparators.forType(type);
if (cmp.compare(value1, value2) > 0) {
ByteBuffer lowerBuffer = Conversions.toByteBuffer(type, value2);
ByteBuffer upperBuffer = Conversions.toByteBuffer(type, value1);
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestFileGenerationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.iceberg.types.Types;
import org.apache.iceberg.types.Types.NestedField;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class TestFileGenerationUtil {

Expand Down Expand Up @@ -85,6 +87,23 @@ public void testBoundsWithSpecificValues() {
assertThat(actualIntUpper).isEqualTo(intUpper);
}

@ParameterizedTest
@ValueSource(strings = {"none", "counts", "truncate(16)", "full"})
@SuppressWarnings("deprecation")
void testBoundsForAllMetricsModes(String metricsMode) {
MetricsConfig metricsConfig =
MetricsConfig.fromProperties(
ImmutableMap.of(TableProperties.DEFAULT_WRITE_METRICS_MODE, metricsMode));
Metrics metrics =
FileGenerationUtil.generateRandomMetrics(
SCHEMA,
metricsConfig,
ImmutableMap.of() /* no lower bounds */,
ImmutableMap.of() /* no upper bounds */);

checkBounds(metrics, metricsConfig);
}

private void checkBounds(Metrics metrics, MetricsConfig metricsConfig) {
for (NestedField field : SCHEMA.columns()) {
MetricsMode mode = metricsConfig.columnMode(field.name());
Expand Down
Loading