You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by yo...@apache.org on 2022/09/23 08:08:46 UTC
[superset] branch master updated: feat: support multiple columns with time grain in Table Chart (#21547)
This is an automated email from the ASF dual-hosted git repository.
yongjiezhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new d67b04683c feat: support multiple columns with time grain in Table Chart (#21547)
d67b04683c is described below
commit d67b04683c5e671a8e0278994fb36b23978c1ff4
Author: Yongjie Zhao <yo...@apache.org>
AuthorDate: Fri Sep 23 16:08:35 2022 +0800
feat: support multiple columns with time grain in Table Chart (#21547)
---
.../plugins/plugin-chart-table/src/buildQuery.ts | 25 ++++++++++++++-
.../plugin-chart-table/src/controlPanel.tsx | 37 +++++++++++++++++++++-
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts b/superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts
index 99a0da8ca9..cf074310da 100644
--- a/superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts
+++ b/superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts
@@ -17,9 +17,13 @@
* under the License.
*/
import {
+ AdhocColumn,
buildQueryContext,
ensureIsArray,
+ FeatureFlag,
getMetricLabel,
+ isFeatureEnabled,
+ isPhysicalColumn,
QueryMode,
QueryObject,
removeDuplicates,
@@ -63,7 +67,7 @@ const buildQuery: BuildQuery<TableChartFormData> = (
}
return buildQueryContext(formDataCopy, baseQueryObject => {
- let { metrics, orderby = [] } = baseQueryObject;
+ let { metrics, orderby = [], columns = [] } = baseQueryObject;
let postProcessing: PostProcessingRule[] = [];
if (queryMode === QueryMode.aggregate) {
@@ -95,6 +99,24 @@ const buildQuery: BuildQuery<TableChartFormData> = (
},
];
}
+
+ columns = columns.map(col => {
+ if (
+ isPhysicalColumn(col) &&
+ formData.time_grain_sqla &&
+ isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) &&
+ formData?.datetime_columns_lookup?.[col]
+ ) {
+ return {
+ timeGrain: formData.time_grain_sqla,
+ columnType: 'BASE_AXIS',
+ sqlExpression: col,
+ label: col,
+ expressionType: 'SQL',
+ } as AdhocColumn;
+ }
+ return col;
+ });
}
const moreProps: Partial<QueryObject> = {};
@@ -108,6 +130,7 @@ const buildQuery: BuildQuery<TableChartFormData> = (
let queryObject = {
...baseQueryObject,
+ columns,
orderby,
metrics,
post_processing: postProcessing,
diff --git a/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx b/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
index 03082cb21c..e26481964d 100644
--- a/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
+++ b/superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx
@@ -23,7 +23,9 @@ import {
ensureIsArray,
FeatureFlag,
GenericDataType,
+ isAdhocColumn,
isFeatureEnabled,
+ isPhysicalColumn,
QueryFormColumn,
QueryMode,
smartDateFormatter,
@@ -145,7 +147,7 @@ const percentMetricsControl: typeof sharedControls.metrics = {
const config: ControlPanelConfig = {
controlPanelSections: [
- sections.legacyTimeseriesTime,
+ sections.genericTime,
{
label: t('Query'),
expanded: true,
@@ -186,6 +188,39 @@ const config: ControlPanelConfig = {
},
},
],
+ [
+ isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && isAggMode
+ ? {
+ name: 'time_grain_sqla',
+ config: {
+ ...sharedControls.time_grain_sqla,
+ visibility: ({ controls }) => {
+ const dttmLookup = Object.fromEntries(
+ ensureIsArray(controls?.groupby?.options).map(option => [
+ option.column_name,
+ option.is_dttm,
+ ]),
+ );
+
+ return ensureIsArray(controls?.groupby.value)
+ .map(selection => {
+ if (isAdhocColumn(selection)) {
+ return true;
+ }
+ if (isPhysicalColumn(selection)) {
+ return !!dttmLookup[selection];
+ }
+ return false;
+ })
+ .some(Boolean);
+ },
+ },
+ }
+ : null,
+ isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) && isAggMode
+ ? 'datetime_columns_lookup'
+ : null,
+ ],
[
{
name: 'metrics',