Skip to content

Commit

Permalink
fix(bigquery): fix integer to timestamp casting
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and gforsyth committed Jan 9, 2023
1 parent 9c0e775 commit f5bacad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def bigquery_cast_timestamp_to_integer(compiled_arg, from_, to):
return f"UNIX_MICROS({compiled_arg})"


@bigquery_cast.register(str, dt.Integer, dt.Timestamp)
def bigquery_cast_integer_to_timestamp(compiled_arg, from_, to):
"""Convert INT64 (seconds since Unix epoch) to Timestamp."""
return f"TIMESTAMP_SECONDS({compiled_arg})"


@bigquery_cast.register(str, dt.DataType, dt.DataType)
def bigquery_cast_generate(compiled_arg, from_, to):
"""Cast to desired type."""
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 @@ -873,15 +873,15 @@ def test_timestamp_extract_milliseconds_with_big_value(con):
assert result == 333


@pytest.mark.notimpl(["bigquery", "datafusion"])
@pytest.mark.notimpl(["datafusion"])
def test_integer_cast_to_timestamp_column(backend, alltypes, df):
expr = alltypes.int_col.cast("timestamp")
expected = pd.to_datetime(df.int_col, unit="s").rename(expr.get_name())
result = expr.execute()
backend.assert_series_equal(result, expected)


@pytest.mark.notimpl(["bigquery", "datafusion"])
@pytest.mark.notimpl(["datafusion"])
def test_integer_cast_to_timestamp_scalar(alltypes, df):
expr = alltypes.int_col.min().cast("timestamp")
result = expr.execute()
Expand Down

0 comments on commit f5bacad

Please sign in to comment.