From 3b35ddf135b882bc342fac26c6bd4db52fe3b968 Mon Sep 17 00:00:00 2001 From: Teemu Haapoja Date: Wed, 7 Feb 2018 18:18:11 +0200 Subject: [PATCH] convert postgresql date_trunc() to UTC to prevent pandas error (#4319) * cast postgresql date_trunc() to timestamp without time zone to prevent pandas error * fix formatting for flake8 * change cast to timezone conversion instead --- superset/db_engine_specs.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index e24627cc33..c6496dbccd 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -288,14 +288,22 @@ class PostgresBaseEngineSpec(BaseEngineSpec): time_grains = ( Grain('Time Column', _('Time Column'), '{col}'), - Grain('second', _('second'), "DATE_TRUNC('second', {col})"), - Grain('minute', _('minute'), "DATE_TRUNC('minute', {col})"), - Grain('hour', _('hour'), "DATE_TRUNC('hour', {col})"), - Grain('day', _('day'), "DATE_TRUNC('day', {col})"), - Grain('week', _('week'), "DATE_TRUNC('week', {col})"), - Grain('month', _('month'), "DATE_TRUNC('month', {col})"), - Grain('quarter', _('quarter'), "DATE_TRUNC('quarter', {col})"), - Grain('year', _('year'), "DATE_TRUNC('year', {col})"), + Grain('second', _('second'), + "DATE_TRUNC('second', {col}) AT TIME ZONE 'UTC'"), + Grain('minute', _('minute'), + "DATE_TRUNC('minute', {col}) AT TIME ZONE 'UTC'"), + Grain('hour', _('hour'), + "DATE_TRUNC('hour', {col}) AT TIME ZONE 'UTC'"), + Grain('day', _('day'), + "DATE_TRUNC('day', {col}) AT TIME ZONE 'UTC'"), + Grain('week', _('week'), + "DATE_TRUNC('week', {col}) AT TIME ZONE 'UTC'"), + Grain('month', _('month'), + "DATE_TRUNC('month', {col}) AT TIME ZONE 'UTC'"), + Grain('quarter', _('quarter'), + "DATE_TRUNC('quarter', {col}) AT TIME ZONE 'UTC'"), + Grain('year', _('year'), + "DATE_TRUNC('year', {col}) AT TIME ZONE 'UTC'"), ) @classmethod