From ee74e3a67363ee81ae6e755ce55b8b7045cf1f90 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Mon, 30 Jan 2023 16:25:00 +0100 Subject: [PATCH] feat(clickhouse): implement ops.ExtractMillisecond --- ibis/backends/clickhouse/compiler/values.py | 6 ++++++ ibis/backends/tests/test_temporal.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ibis/backends/clickhouse/compiler/values.py b/ibis/backends/clickhouse/compiler/values.py index 020a3ea9cb8c..15c675b9c7f2 100644 --- a/ibis/backends/clickhouse/compiler/values.py +++ b/ibis/backends/clickhouse/compiler/values.py @@ -1085,6 +1085,12 @@ def _fmt(op, _name: str = _name, **kw): del _fmt, _name, _op +@translate_val.register(ops.ExtractMillisecond) +def _extract_millisecond(op, **kw): + arg = translate_val(op.arg, **kw) + return f"substring(formatDateTime({arg}, '%f'), 1, 3)" + + @translate_val.register def _sort_key(op: ops.SortKey, **kw): arg = translate_val(op.expr, **kw) diff --git a/ibis/backends/tests/test_temporal.py b/ibis/backends/tests/test_temporal.py index 538446b09b4e..8594db68e9c6 100644 --- a/ibis/backends/tests/test_temporal.py +++ b/ibis/backends/tests/test_temporal.py @@ -98,7 +98,7 @@ def test_timestamp_extract_literal(con, func, expected): assert con.execute(func(value).name("tmp")) == expected -@pytest.mark.notimpl(["datafusion", "clickhouse"]) +@pytest.mark.notimpl(["datafusion"]) @pytest.mark.notyet(["sqlite", "pyspark"]) def test_timestamp_extract_milliseconds(backend, alltypes, df): expr = alltypes.timestamp_col.millisecond().name("millisecond") @@ -863,7 +863,7 @@ def test_date_column_from_iso(con, alltypes, df): @pytest.mark.notimpl(["datafusion"]) -@pytest.mark.notyet(["clickhouse", "pyspark"]) +@pytest.mark.notyet(["pyspark"]) def test_timestamp_extract_milliseconds_with_big_value(con): timestamp = ibis.timestamp("2021-01-01 01:30:59.333456") millis = timestamp.millisecond()