Skip to content

Commit e2c2fca

Browse files
committed
duckdb: don't push down aggregation over floats
1 parent b6c85f0 commit e2c2fca

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

vortex-duckdb/src/table_function.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,19 @@ pub fn pushdown_projection_aggregates(
683683
debug!(%expr, %i, "failed to push down projection aggregate");
684684
return Ok(false);
685685
};
686+
687+
// TODO(myrrc): DuckDB treats NaN as a normal value ordered greater than
688+
// everything which is substandard. vortex aggregations just skip nan.
689+
// don't push aggregations on floats until resolved
690+
// See slt/duckdb/nan_aggregates.slt.
691+
let projection_id_usize: usize = projection_id.as_();
692+
if bind_data.column_fields[projection_id_usize]
693+
.dtype
694+
.is_float()
695+
{
696+
return Ok(false);
697+
}
698+
686699
debug!(%expr, %projection_id, %i, "pushed down projection aggregate");
687700
aggregates.push(ColumnAggregate::Real {
688701
projection_id,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
# Vortex aggregate pushdown must match DuckDB's NaN semantics
5+
6+
include ../setup.slt.no
7+
8+
statement ok
9+
COPY (
10+
SELECT * FROM (VALUES
11+
('nan'::DOUBLE),
12+
(1.0),
13+
(2.0),
14+
(CAST(NULL AS DOUBLE))
15+
) AS t(x)
16+
) TO '${WORK_DIR}/nan-agg.vortex';
17+
18+
query TT
19+
EXPLAIN
20+
SELECT count(*), count(x), sum(x), min(x), max(x), avg(x)
21+
FROM '${WORK_DIR}/nan-agg.vortex';
22+
----
23+
<REGEX>:.*UNGROUPED_AGGREGATE.*
24+
25+
query II
26+
SELECT count(*), count(x) FROM '${WORK_DIR}/nan-agg.vortex';
27+
----
28+
4 3
29+
30+
query RR
31+
SELECT sum(x), avg(x) FROM '${WORK_DIR}/nan-agg.vortex';
32+
----
33+
NaN NaN
34+
35+
query RR
36+
SELECT min(x), max(x) FROM '${WORK_DIR}/nan-agg.vortex';
37+
----
38+
1 NaN

0 commit comments

Comments
 (0)