From 894ce90d01df72c2fdb8c24af5b2b9c4bad8412a Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Fri, 20 May 2022 10:56:09 -0700 Subject: [PATCH] feat(duckdb): implement approx_median --- ibis/backends/duckdb/registry.py | 5 +++++ ibis/backends/tests/test_client.py | 1 + 2 files changed, 6 insertions(+) diff --git a/ibis/backends/duckdb/registry.py b/ibis/backends/duckdb/registry.py index 7a9a3308556d..608965ba503f 100644 --- a/ibis/backends/duckdb/registry.py +++ b/ibis/backends/duckdb/registry.py @@ -167,6 +167,11 @@ def _regex_extract(t, expr): ops.RegexExtract: _regex_extract, ops.RegexReplace: fixed_arity(sa.func.regexp_replace, 3), ops.StringContains: fixed_arity(sa.func.contains, 2), + ops.CMSMedian: reduction( + # without inline text, duckdb fails with + # RuntimeError: INTERNAL Error: Invalid PhysicalType for GetTypeIdSize # noqa: E501 + lambda arg: sa.func.approx_quantile(arg, sa.text(str(0.5))) + ), ops.HLLCardinality: reduction(sa.func.approx_count_distinct), } ) diff --git a/ibis/backends/tests/test_client.py b/ibis/backends/tests/test_client.py index 3b90b061b18c..21686cb12ad2 100644 --- a/ibis/backends/tests/test_client.py +++ b/ibis/backends/tests/test_client.py @@ -337,6 +337,7 @@ def test_verify(ddl_backend, ddl_con): assert ddl_backend.api.verify(expr) +@pytest.mark.never(["duckdb"], reason="duckdb supports approximate median") def test_not_verify(alchemy_con, alchemy_backend): # There is no expression that can't be compiled to any backend # Testing `not verify()` only for an expression not supported in postgres