Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
PARQUET-1246: Changes according to zi's comments
  • Loading branch information
Gabor Szadovszky committed Mar 14, 2018
commit 20e93329904b88bce88495e916118d1eab4f100b
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ public Statistics<?> build() {
((Statistics<?>) stats).hasNonNullValue = false;
} else {
// Updating min to -0.0 and max to +0.0 to ensure that no 0.0 values would be skipped
if (min == 0.0f) {
stats.setMinMax(-0.0f, max);
if (Float.compare(min, 0.0f) == 0) {
min = -0.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) In my opinion,

min = -0.0f;
stats.setMinMax(min, max);

would be cleaner. Similar for the max case (although max is not used any more in this function).

stats.setMinMax(min, max);
}
if (max == -0.0f) {
stats.setMinMax(min, 0.0f);
if (Float.compare(max, -0.0f) == 0) {
max = 0.0f;
stats.setMinMax(min, max);
}
}
}
Expand All @@ -124,12 +125,13 @@ public Statistics<?> build() {
((Statistics<?>) stats).hasNonNullValue = false;
} else {
// Updating min to -0.0 and max to +0.0 to ensure that no 0.0 values would be skipped
if (min == 0.0) {
stats.setMinMax(-0.0, max);
if (Double.compare(min, 0.0) == 0) {
min = -0.0;
stats.setMinMax(min, max);
}
if (max == -0.0) {
stats.setMinMax(min, 0.0);
if (Double.compare(max, -0.0) == 0) {
max = 0.0;
stats.setMinMax(min, max);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,24 @@ public void testSpecBuilderForFloat() {
assertTrue(stats.isNumNullsSet());
assertEquals(42, stats.getNumNulls());
assertFalse(stats.hasNonNullValue());

builder = Statistics.getBuilderForReading(type);
stats = builder.withMin(intToBytes(floatToIntBits(0.0f)))
.withMax(intToBytes(floatToIntBits(42.0f))).build();
assertEquals(0, Float.compare(-0.0f, (Float) stats.genericGetMin()));
assertEquals(0, Float.compare(42.0f, (Float) stats.genericGetMax()));

builder = Statistics.getBuilderForReading(type);
stats = builder.withMin(intToBytes(floatToIntBits(-42.0f)))
.withMax(intToBytes(floatToIntBits(-0.0f))).build();
assertEquals(0, Float.compare(-42.0f, (Float) stats.genericGetMin()));
assertEquals(0, Float.compare(0.0f, (Float) stats.genericGetMax()));

builder = Statistics.getBuilderForReading(type);
stats = builder.withMin(intToBytes(floatToIntBits(0.0f)))
.withMax(intToBytes(floatToIntBits(-0.0f))).build();
assertEquals(0, Float.compare(-0.0f, (Float) stats.genericGetMin()));
assertEquals(0, Float.compare(0.0f, (Float) stats.genericGetMax()));
}

@Test
Expand All @@ -749,5 +767,23 @@ public void testSpecBuilderForDouble() {
assertTrue(stats.isNumNullsSet());
assertEquals(42, stats.getNumNulls());
assertFalse(stats.hasNonNullValue());

builder = Statistics.getBuilderForReading(type);
stats = builder.withMin(longToBytes(doubleToLongBits(0.0)))
.withMax(longToBytes(doubleToLongBits(42.0))).build();
assertEquals(0, Double.compare(-0.0, (Double) stats.genericGetMin()));
assertEquals(0, Double.compare(42.0, (Double) stats.genericGetMax()));

builder = Statistics.getBuilderForReading(type);
stats = builder.withMin(longToBytes(doubleToLongBits(-42.0)))
.withMax(longToBytes(doubleToLongBits(-0.0))).build();
assertEquals(0, Double.compare(-42.0, (Double) stats.genericGetMin()));
assertEquals(0, Double.compare(0.0, (Double) stats.genericGetMax()));

builder = Statistics.getBuilderForReading(type);
stats = builder.withMin(longToBytes(doubleToLongBits(0.0)))
.withMax(longToBytes(doubleToLongBits(-0.0))).build();
assertEquals(0, Double.compare(-0.0, (Double) stats.genericGetMin()));
assertEquals(0, Double.compare(0.0, (Double) stats.genericGetMax()));
}
}