Skip to content

Commit 5b07d8e

Browse files
devozerovraunaqmorarka
authored andcommitted
Fix DoubleRange resolution for NaN values
1 parent be5daac commit 5b07d8e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

core/trino-spi/src/main/java/io/trino/spi/statistics/DoubleRange.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public static Optional<DoubleRange> from(Type type, Object minTrinoNativeValue,
5252
min,
5353
max));
5454
}
55+
if (isNaN(min.getAsDouble()) || isNaN(max.getAsDouble())) {
56+
return Optional.empty();
57+
}
5558
return Optional.of(new DoubleRange(min.getAsDouble(), max.getAsDouble()));
5659
}
5760

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergStatistics.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,21 @@ public void testStatsAfterDeletingAllRows()
11431143
"(null, null, DOUBLE '25')");
11441144
}
11451145

1146+
@Test
1147+
public void testNaN()
1148+
{
1149+
String tableName = "test_nan";
1150+
assertUpdate("CREATE TABLE " + tableName + " AS SELECT 1 AS c1, double 'NaN' AS c2", 1);
1151+
assertQuery(
1152+
"SHOW STATS FOR " + tableName,
1153+
"""
1154+
VALUES
1155+
('c1', null, 1.0, 0.0, null, 1, 1),
1156+
('c2', null, 1.0, 0.0, null, null, null),
1157+
(null, null, null, null, 1.0, null, null)
1158+
""");
1159+
}
1160+
11461161
private long getCurrentSnapshotId(String tableName)
11471162
{
11481163
return (long) computeActual(format("SELECT snapshot_id FROM \"%s$snapshots\" ORDER BY committed_at DESC FETCH FIRST 1 ROW WITH TIES", tableName))

0 commit comments

Comments
 (0)