From 33509ab7da384144d42d67dd8c6233b1be9c9fa0 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Fri, 16 Sep 2022 15:19:24 +0800 Subject: [PATCH] fix: BigQuery cannot accept Time Grain (#21489) --- .../src/shared-controls/index.tsx | 12 +++++------- superset/connectors/sqla/models.py | 7 ++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx index 03d4698620ca6..9b06bb3b9b075 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx +++ b/superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/index.tsx @@ -57,7 +57,7 @@ import { DEFAULT_NUMBER_FORMAT, } from '../utils'; import { TIME_FILTER_LABELS } from '../constants'; -import { SharedControlConfig, Dataset } from '../types'; +import { SharedControlConfig, Dataset, ColumnMeta } from '../types'; import { dndAdhocFilterControl, @@ -197,12 +197,10 @@ const time_grain_sqla: SharedControlConfig<'SelectControl'> = { if (isAdhocColumn(xAxisValue)) { return true; } - if (isPhysicalColumn(xAxisValue) && Array.isArray(xAxis?.options)) { - for (let i = 0; i < xAxis.options.length; i += 1) { - if (xAxis.options[i].column_name === xAxisValue) { - return !!xAxis.options[i].is_dttm; - } - } + if (isPhysicalColumn(xAxisValue)) { + return !!(xAxis?.options ?? []).find( + (col: ColumnMeta) => col?.column_name === xAxisValue, + )?.is_dttm; } return false; }, diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index a72d07f2d0741..4278f490d997c 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -1144,9 +1144,10 @@ def adhoc_column_to_sqla( and (time_grain := col.get("timeGrain")) ): sqla_column = self.db_engine_spec.get_timestamp_expr( - sqla_column, - None, - time_grain, + col=sqla_column, + pdf=None, + time_grain=time_grain, + type_=str(getattr(sqla_column, "type", "")), ) return self.make_sqla_column_compatible(sqla_column, label)