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 authored and gforsyth committed Oct 20, 2023
1 parent 4d34afc commit 10a5916
Show file tree
Hide file tree
Showing 2 changed files with 19 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
12 changes: 9 additions & 3 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,7 +2518,6 @@ def test_delta(con, start, end, unit, expected):
@pytest.mark.notimpl(
[
"bigquery",
"clickhouse",
"dask",
"datafusion",
"flink",
Expand All @@ -2543,7 +2542,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 @@ -2560,7 +2567,6 @@ def test_timestamp_bucket(backend, kws, pd_freq):
@pytest.mark.notimpl(
[
"bigquery",
"clickhouse",
"dask",
"datafusion",
"flink",
Expand Down

0 comments on commit 10a5916

Please sign in to comment.