Skip to content

Commit

Permalink
feat(clickhouse): add support for timestamp bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Oct 18, 2023
1 parent f87779c commit bd62065
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ibis/backends/clickhouse/compiler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ def _truncate(op, *, arg, unit, **_):
return converter(arg)


@translate_val.register(ops.TimestampBucket)
def _timestamp_bucket(op, *, arg, interval, offset, **_):
if offset is not None:
raise com.UnsupportedOperationError(
"Timestamp bucket with offset is not supported"
)

return F.toStartOfInterval(arg, interval)


@translate_val.register(ops.DateFromYMD)
def _date_from_ymd(op, *, year, month, day, **_):
return F.toDate(
Expand Down
17 changes: 14 additions & 3 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,7 +2502,6 @@ def test_delta(con, start, end, unit, expected):
@pytest.mark.notimpl(
[
"bigquery",
"clickhouse",
"dask",
"datafusion",
"druid",
Expand All @@ -2523,7 +2522,15 @@ def test_delta(con, start, end, unit, expected):
@pytest.mark.parametrize(
"kws, pd_freq",
[
({"milliseconds": 50}, "50ms"),
param(
{"milliseconds": 50},
"50ms",
marks=pytest.mark.notimpl(
["clickhouse"],
raises=com.UnsupportedOperationError,
reason="clickhouse doesn't support sub-second interval precision",
),
),
({"seconds": 2}, "2s"),
({"minutes": 5}, "300s"),
({"hours": 2}, "2h"),
Expand All @@ -2540,7 +2547,6 @@ def test_timestamp_bucket(backend, kws, pd_freq):
@pytest.mark.notimpl(
[
"bigquery",
"clickhouse",
"dask",
"datafusion",
"druid",
Expand All @@ -2558,6 +2564,11 @@ def test_timestamp_bucket(backend, kws, pd_freq):
],
raises=com.OperationNotDefinedError,
)
@pytest.mark.notimpl(
["clickhouse"],
reason="offset arg not supported",
raises=com.UnsupportedOperationError,
)
@pytest.mark.parametrize("offset_mins", [2, -2])
def test_timestamp_bucket_offset(backend, offset_mins):
ts = backend.functional_alltypes.timestamp_col.name("ts")
Expand Down

0 comments on commit bd62065

Please sign in to comment.