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_timegrain_expressions(self): col = column("temporal") test_cases = { "DATE": "DATE_TRUNC(temporal, HOUR)", "TIME": "TIME_TRUNC(temporal, HOUR)", "DATETIME": "DATETIME_TRUNC(temporal, HOUR)", "TIMESTAMP": "TIMESTAMP_TRUNC(temporal, HOUR)", } for type_, expected in test_cases.items(): actual = BigQueryEngineSpec.get_timestamp_expr( col=col, pdf=None, time_grain="PT1H", type_=type_ ) self.assertEqual(str(actual), expected)