feat(bigquery): implement custom minute time grains (#12581)

* feat(bigquery): implement custom minute time grains

* address review comment
This commit is contained in:
Ville Brofeldt
2021-01-19 14:32:33 +02:00
committed by GitHub
parent e7a5d0d01a
commit 7e99d768af
3 changed files with 38 additions and 0 deletions

View File

@@ -74,6 +74,28 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
)
self.assertEqual(str(actual), expected)
def test_custom_minute_timegrain_expressions(self):
"""
DB Eng Specs (bigquery): Test time grain expressions
"""
col = column("temporal")
test_cases = {
"DATE": "CAST(TIMESTAMP_SECONDS("
"5*60 * DIV(UNIX_SECONDS(CAST(temporal AS TIMESTAMP)), 5*60)"
") AS DATE)",
"DATETIME": "CAST(TIMESTAMP_SECONDS("
"5*60 * DIV(UNIX_SECONDS(CAST(temporal AS TIMESTAMP)), 5*60)"
") AS DATETIME)",
"TIMESTAMP": "CAST(TIMESTAMP_SECONDS("
"5*60 * DIV(UNIX_SECONDS(CAST(temporal AS TIMESTAMP)), 5*60)"
") AS TIMESTAMP)",
}
for type_, expected in test_cases.items():
actual = BigQueryEngineSpec.get_timestamp_expr(
col=col, pdf=None, time_grain="PT5M", type_=type_
)
assert str(actual) == expected
def test_fetch_data(self):
"""
DB Eng Specs (bigquery): Test fetch data