Skip to content

Commit

Permalink
feat(bigquery): support timestamp bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and jcrist committed Jul 30, 2024
1 parent bd8c93f commit fd61f2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
16 changes: 15 additions & 1 deletion ibis/backends/sql/compilers/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class BigQueryCompiler(SQLGlotCompiler):
ops.MultiQuantile,
ops.RegexSplit,
ops.RowID,
ops.TimestampBucket,
ops.TimestampDiff,
)

Expand Down Expand Up @@ -760,3 +759,18 @@ def visit_TableUnnest(
.from_(parent)
.join(unnest, join_type="CROSS" if not keep_empty else "LEFT")
)

def visit_TimestampBucket(self, op, *, arg, interval, offset):
arg_dtype = op.arg.dtype
if arg_dtype.timezone is not None:
funcname = "timestamp"
else:
funcname = "datetime"

func = self.f[f"{funcname}_bucket"]

origin = sge.convert("1970-01-01")
if offset is not None:
origin = self.f.anon[f"{funcname}_add"](origin, offset)

return func(arg, interval, origin)
13 changes: 1 addition & 12 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,17 +2041,7 @@ def test_delta(con, start, end, unit, expected):


@pytest.mark.notimpl(
[
"bigquery",
"dask",
"impala",
"mysql",
"pandas",
"pyspark",
"sqlite",
"trino",
"druid",
],
["dask", "impala", "mysql", "pandas", "pyspark", "sqlite", "trino", "druid"],
raises=com.OperationNotDefinedError,
)
@pytest.mark.parametrize(
Expand Down Expand Up @@ -2154,7 +2144,6 @@ def test_timestamp_bucket(backend, kws, pd_freq):

@pytest.mark.notimpl(
[
"bigquery",
"dask",
"datafusion",
"impala",
Expand Down

0 comments on commit fd61f2c

Please sign in to comment.