Skip to content

Commit

Permalink
fix(bigquery): generate the correct temporal literal type based on th…
Browse files Browse the repository at this point in the history
…e presence of timezone information
  • Loading branch information
cpcloud committed Sep 27, 2023
1 parent 6b1218a commit 98a6ae0
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def _literal(t, op):
value = value.date()
return f"DATE {_sg_literal(str(value))}"
elif dtype.is_timestamp():
return f"TIMESTAMP {_sg_literal(str(value))}"
typename = "DATETIME" if dtype.timezone is None else "TIMESTAMP"
return f"{typename} {_sg_literal(str(value))}"
elif dtype.is_time():
# TODO: define extractors on TimeValue expressions
return f"TIME {_sg_literal(str(value))}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
MOD(EXTRACT(DAYOFWEEK FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
MOD(EXTRACT(DAYOFWEEK FROM CAST('2017-01-01 04:55:59' AS DATETIME)) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
INITCAP(CAST(CAST('2017-01-01 04:55:59' AS TIMESTAMP) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
INITCAP(CAST(CAST('2017-01-01 04:55:59' AS DATETIME) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
MOD(EXTRACT(DAYOFWEEK FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
MOD(EXTRACT(DAYOFWEEK FROM CAST('2017-01-01 04:55:59' AS DATETIME)) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
INITCAP(CAST(CAST('2017-01-01 04:55:59' AS TIMESTAMP) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
INITCAP(CAST(CAST('2017-01-01 04:55:59' AS DATETIME) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
MOD(EXTRACT(DAYOFWEEK FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
MOD(EXTRACT(DAYOFWEEK FROM CAST('2017-01-01 04:55:59' AS DATETIME)) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
INITCAP(CAST(CAST('2017-01-01 04:55:59' AS TIMESTAMP) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
INITCAP(CAST(CAST('2017-01-01 04:55:59' AS DATETIME) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
EXTRACT(hour FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) AS `tmp`
EXTRACT(hour FROM CAST('2017-01-01 04:55:59' AS DATETIME)) AS `tmp`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
EXTRACT(hour FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) AS `tmp`
EXTRACT(hour FROM CAST('2017-01-01 04:55:59' AS DATETIME)) AS `tmp`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
EXTRACT(hour FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) AS `tmp`
EXTRACT(hour FROM CAST('2017-01-01 04:55:59' AS DATETIME)) AS `tmp`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
EXTRACT(year FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
EXTRACT(year FROM CAST('2017-01-01 04:55:59' AS DATETIME)) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
EXTRACT(year FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
EXTRACT(year FROM CAST('2017-01-01 04:55:59' AS DATETIME)) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT
EXTRACT(year FROM CAST('2017-01-01 04:55:59' AS TIMESTAMP)) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
EXTRACT(year FROM CAST('2017-01-01 04:55:59' AS DATETIME)) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59`
11 changes: 6 additions & 5 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,12 @@ def test_timestamp_comparison_filter(backend, con, alltypes, df, func_name):
raises=BaseException, # pyo3_runtime.PanicException is not a subclass of Exception
reason="failed to determine supertype of datetime[ns, UTC] and datetime[ns]",
)
@pytest.mark.never(
["bigquery"],
raises=GoogleBadRequest,
# perhaps we should consider disallowing this in ibis as well
reason="BigQuery doesn't support comparing DATETIME and TIMESTAMP; numpy doesn't support timezones",
)
def test_timestamp_comparison_filter_numpy(backend, con, alltypes, df, func_name):
ts = np.datetime64("2010-03-02 00:00:00.000123")

Expand Down Expand Up @@ -2215,11 +2221,6 @@ def test_integer_cast_to_timestamp_scalar(alltypes, df):
reason="PySpark doesn't handle big timestamps",
raises=pd.errors.OutOfBoundsDatetime,
)
@pytest.mark.notimpl(
["bigquery"],
reason="bigquery returns a datetime with a timezone",
raises=AssertionError,
)
def test_big_timestamp(con):
# TODO: test with a timezone
value = ibis.timestamp("2419-10-11 10:10:25")
Expand Down

0 comments on commit 98a6ae0

Please sign in to comment.