From 8a500bc61c7259de6101715d5b328deda077a543 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Fri, 20 May 2022 10:15:59 -0700 Subject: [PATCH] feat(duckdb): implement arbitrary first and last aggregation --- ibis/backends/duckdb/registry.py | 7 +++++++ ibis/backends/tests/test_aggregation.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ibis/backends/duckdb/registry.py b/ibis/backends/duckdb/registry.py index 1c892a0347a6..c53ccd5c1c46 100644 --- a/ibis/backends/duckdb/registry.py +++ b/ibis/backends/duckdb/registry.py @@ -159,6 +159,12 @@ def _strftime(t, expr): ) +def _arbitrary(t, expr): + if (how := expr.op().how) == "heavy": + raise ValueError(f"how={how!r} not supported in the DuckDB backend") + return t._reduction(getattr(sa.func, how), expr) + + operation_registry.update( { ops.ArrayColumn: _array_column, @@ -187,6 +193,7 @@ def _strftime(t, expr): ), ops.HLLCardinality: reduction(sa.func.approx_count_distinct), ops.Strftime: _strftime, + ops.Arbitrary: _arbitrary, } ) diff --git a/ibis/backends/tests/test_aggregation.py b/ibis/backends/tests/test_aggregation.py index fb810c23788c..ec6a7042df91 100644 --- a/ibis/backends/tests/test_aggregation.py +++ b/ibis/backends/tests/test_aggregation.py @@ -238,7 +238,7 @@ def test_aggregate_grouped( lambda t, where: t.double_col[where].iloc[0], id='arbitrary_first', marks=pytest.mark.notimpl( - ['impala', 'postgres', 'mysql', 'sqlite', 'duckdb'] + ['impala', 'postgres', 'mysql', 'sqlite'] ), ), param( @@ -246,7 +246,7 @@ def test_aggregate_grouped( lambda t, where: t.double_col[where].iloc[-1], id='arbitrary_last', marks=pytest.mark.notimpl( - ['impala', 'postgres', 'mysql', 'sqlite', 'duckdb'] + ['impala', 'postgres', 'mysql', 'sqlite'] ), ), param(