Skip to content

Commit

Permalink
feat(clickhouse): implement ops.ExtractMillisecond
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Jan 30, 2023
1 parent 05f5ae5 commit ee74e3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/clickhouse/compiler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ee74e3a

Please sign in to comment.