From 9e6a3e1a4e4d4ef77b158bde80352de8fe794a3a Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Tue, 21 Jun 2022 10:06:52 -0300 Subject: [PATCH] fix(viz): BigQuery time grain 'minute'/'second' throws an error (#20350) (cherry picked from commit 5afeba34bd72526844d0f71764309a6669d96c5a) --- superset/db_engine_specs/bigquery.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/superset/db_engine_specs/bigquery.py b/superset/db_engine_specs/bigquery.py index e33457c79abb1..51fd710ab3352 100644 --- a/superset/db_engine_specs/bigquery.py +++ b/superset/db_engine_specs/bigquery.py @@ -123,8 +123,12 @@ class BigQueryEngineSpec(BaseEngineSpec): _time_grain_expressions = { None: "{col}", - "PT1S": "{func}({col}, SECOND)", - "PT1M": "{func}({col}, MINUTE)", + "PT1S": "CAST(TIMESTAMP_SECONDS(" + "UNIX_SECONDS(CAST({col} AS TIMESTAMP))" + ") AS {type})", + "PT1M": "CAST(TIMESTAMP_SECONDS(" + "60 * DIV(UNIX_SECONDS(CAST({col} AS TIMESTAMP)), 60)" + ") AS {type})", "PT5M": "CAST(TIMESTAMP_SECONDS(" "5*60 * DIV(UNIX_SECONDS(CAST({col} AS TIMESTAMP)), 5*60)" ") AS {type})",