Skip to content

Commit

Permalink
feat(duckdb): implement arbitrary first and last aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed May 23, 2022
1 parent 5c96498 commit 8a500bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ibis/backends/duckdb/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -187,6 +193,7 @@ def _strftime(t, expr):
),
ops.HLLCardinality: reduction(sa.func.approx_count_distinct),
ops.Strftime: _strftime,
ops.Arbitrary: _arbitrary,
}
)

Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ 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(
lambda t, where: t.double_col.arbitrary(how='last', where=where),
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(
Expand Down

0 comments on commit 8a500bc

Please sign in to comment.