Skip to content

Commit 20e9332

Browse files
author
Gabor Szadovszky
committed
PARQUET-1246: Changes according to zi's comments
1 parent 3447938 commit 20e9332

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

parquet-column/src/main/java/org/apache/parquet/column/statistics/Statistics.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ public Statistics<?> build() {
9292
((Statistics<?>) stats).hasNonNullValue = false;
9393
} else {
9494
// Updating min to -0.0 and max to +0.0 to ensure that no 0.0 values would be skipped
95-
if (min == 0.0f) {
96-
stats.setMinMax(-0.0f, max);
95+
if (Float.compare(min, 0.0f) == 0) {
9796
min = -0.0f;
97+
stats.setMinMax(min, max);
9898
}
99-
if (max == -0.0f) {
100-
stats.setMinMax(min, 0.0f);
99+
if (Float.compare(max, -0.0f) == 0) {
100+
max = 0.0f;
101+
stats.setMinMax(min, max);
101102
}
102103
}
103104
}
@@ -124,12 +125,13 @@ public Statistics<?> build() {
124125
((Statistics<?>) stats).hasNonNullValue = false;
125126
} else {
126127
// Updating min to -0.0 and max to +0.0 to ensure that no 0.0 values would be skipped
127-
if (min == 0.0) {
128-
stats.setMinMax(-0.0, max);
128+
if (Double.compare(min, 0.0) == 0) {
129129
min = -0.0;
130+
stats.setMinMax(min, max);
130131
}
131-
if (max == -0.0) {
132-
stats.setMinMax(min, 0.0);
132+
if (Double.compare(max, -0.0) == 0) {
133+
max = 0.0;
134+
stats.setMinMax(min, max);
133135
}
134136
}
135137
}

parquet-column/src/test/java/org/apache/parquet/column/statistics/TestStatistics.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,24 @@ public void testSpecBuilderForFloat() {
724724
assertTrue(stats.isNumNullsSet());
725725
assertEquals(42, stats.getNumNulls());
726726
assertFalse(stats.hasNonNullValue());
727+
728+
builder = Statistics.getBuilderForReading(type);
729+
stats = builder.withMin(intToBytes(floatToIntBits(0.0f)))
730+
.withMax(intToBytes(floatToIntBits(42.0f))).build();
731+
assertEquals(0, Float.compare(-0.0f, (Float) stats.genericGetMin()));
732+
assertEquals(0, Float.compare(42.0f, (Float) stats.genericGetMax()));
733+
734+
builder = Statistics.getBuilderForReading(type);
735+
stats = builder.withMin(intToBytes(floatToIntBits(-42.0f)))
736+
.withMax(intToBytes(floatToIntBits(-0.0f))).build();
737+
assertEquals(0, Float.compare(-42.0f, (Float) stats.genericGetMin()));
738+
assertEquals(0, Float.compare(0.0f, (Float) stats.genericGetMax()));
739+
740+
builder = Statistics.getBuilderForReading(type);
741+
stats = builder.withMin(intToBytes(floatToIntBits(0.0f)))
742+
.withMax(intToBytes(floatToIntBits(-0.0f))).build();
743+
assertEquals(0, Float.compare(-0.0f, (Float) stats.genericGetMin()));
744+
assertEquals(0, Float.compare(0.0f, (Float) stats.genericGetMax()));
727745
}
728746

729747
@Test
@@ -749,5 +767,23 @@ public void testSpecBuilderForDouble() {
749767
assertTrue(stats.isNumNullsSet());
750768
assertEquals(42, stats.getNumNulls());
751769
assertFalse(stats.hasNonNullValue());
770+
771+
builder = Statistics.getBuilderForReading(type);
772+
stats = builder.withMin(longToBytes(doubleToLongBits(0.0)))
773+
.withMax(longToBytes(doubleToLongBits(42.0))).build();
774+
assertEquals(0, Double.compare(-0.0, (Double) stats.genericGetMin()));
775+
assertEquals(0, Double.compare(42.0, (Double) stats.genericGetMax()));
776+
777+
builder = Statistics.getBuilderForReading(type);
778+
stats = builder.withMin(longToBytes(doubleToLongBits(-42.0)))
779+
.withMax(longToBytes(doubleToLongBits(-0.0))).build();
780+
assertEquals(0, Double.compare(-42.0, (Double) stats.genericGetMin()));
781+
assertEquals(0, Double.compare(0.0, (Double) stats.genericGetMax()));
782+
783+
builder = Statistics.getBuilderForReading(type);
784+
stats = builder.withMin(longToBytes(doubleToLongBits(0.0)))
785+
.withMax(longToBytes(doubleToLongBits(-0.0))).build();
786+
assertEquals(0, Double.compare(-0.0, (Double) stats.genericGetMin()));
787+
assertEquals(0, Double.compare(0.0, (Double) stats.genericGetMax()));
752788
}
753789
}

0 commit comments

Comments
 (0)