rebenitez1802 commented on code in PR #46008:
URL: https://github.com/apache/superset/pull/46008#discussion_r4472150354
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts:
##########
@@ -186,31 +187,32 @@ export const buildQueryUncached:
BuildQuery<TableChartFormData> = (
}
const temporalColumnsLookup = formData?.temporal_columns_lookup;
- // Filter out the column if needed and prepare the temporal column object
-
- columns = columns.filter(col => {
- const shouldBeAdded =
+ let firstTemporalColumn: AdhocColumn | undefined;
+ columns = columns.map(col => {
+ if (
isPhysicalColumn(col) &&
time_grain_sqla &&
- temporalColumnsLookup?.[col];
-
- if (shouldBeAdded && !temporalColumnAdded) {
- temporalColumn = {
+ temporalColumnsLookup?.[col]
+ ) {
+ const temporalColumn: AdhocColumn = {
timeGrain: time_grain_sqla,
columnType: 'BASE_AXIS',
sqlExpression: col,
label: col,
expressionType: 'SQL',
- } as AdhocColumn;
- temporalColumnAdded = true;
- return false; // Do not include this in the output; it's added
separately
+ ...(isSemanticView ? { isColumnReference: true } : {}),
Review Comment:
🔴 Blocker (embedded guest 403, see review body): mark every grained physical
temporal column as a column reference, not only on semantic views. Without it,
the guest payload check can't match the 2nd+ temporal column against charts
saved before this change. SQL is unchanged for columns in dataset metadata.
```suggestion
isColumnReference: true,
```
##########
superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts:
##########
@@ -218,32 +215,32 @@ export const buildQuery: BuildQuery<TableChartFormData> =
(
}
const temporalColumnsLookup = formData?.temporal_columns_lookup;
- // Filter out the column if needed and prepare the temporal column object
-
- columns = columns.filter(col => {
- const shouldBeAdded =
+ let firstTemporalColumn: AdhocColumn | undefined;
+ columns = columns.map(col => {
+ if (
isPhysicalColumn(col) &&
time_grain_sqla &&
- temporalColumnsLookup?.[col];
-
- if (shouldBeAdded && !temporalColumnAdded) {
- temporalColumn = {
+ temporalColumnsLookup?.[col]
+ ) {
+ const temporalColumn: AdhocColumn = {
timeGrain: time_grain_sqla,
columnType: 'BASE_AXIS',
sqlExpression: col,
label: col,
expressionType: 'SQL',
...(isSemanticView ? { isColumnReference: true } : {}),
Review Comment:
🔴 Blocker (embedded guest 403, see review body): mark every grained physical
temporal column as a column reference, not only on semantic views. Without it,
the guest payload check can't match the 2nd+ temporal column against charts
saved before this change. SQL is unchanged for columns in dataset metadata.
```suggestion
isColumnReference: true,
```
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts:
##########
@@ -33,6 +33,7 @@ import {
removeDuplicates,
PostProcessingRule,
BuildQuery,
+ DatasourceType,
Review Comment:
Follow-up to the `isColumnReference: true` suggestion below:
`DatasourceType` becomes unused.
```suggestion
```
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/src/buildQuery.ts:
##########
@@ -75,6 +76,9 @@ export const buildQueryUncached:
BuildQuery<TableChartFormData> = (
extra_form_data,
} = formData;
const queryMode = getQueryMode(formData);
+ const isSemanticView = formData.datasource?.endsWith(
+ `__${DatasourceType.SemanticView}`,
+ );
Review Comment:
Follow-up to the `isColumnReference: true` suggestion below:
`isSemanticView` becomes unused.
```suggestion
```
##########
superset-frontend/plugins/plugin-chart-ag-grid-table/test/buildQuery.test.ts:
##########
@@ -60,6 +60,63 @@ const createAdhocColumn = (
expressionType: 'SQL',
});
+test('applies grain to every temporal dimension and keeps the first axis
first', () => {
+ const grain = 'P1M';
+ const query = buildQueryUncached({
+ ...basicFormData,
+ groupby: ['category', 'EndDate', 'StartDate'],
+ time_grain_sqla: grain,
+ temporal_columns_lookup: { EndDate: true, StartDate: true },
+ }).queries[0];
+
+ expect(query.columns).toEqual([
+ {
+ timeGrain: grain,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'EndDate',
+ label: 'EndDate',
+ expressionType: 'SQL',
+ },
+ 'category',
+ {
+ timeGrain: grain,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'StartDate',
+ label: 'StartDate',
+ expressionType: 'SQL',
+ },
+ ]);
Review Comment:
Matching expectation update for the `isColumnReference: true` change.
```suggestion
expect(query.columns).toEqual([
{
timeGrain: grain,
columnType: 'BASE_AXIS',
sqlExpression: 'EndDate',
label: 'EndDate',
expressionType: 'SQL',
isColumnReference: true,
},
'category',
{
timeGrain: grain,
columnType: 'BASE_AXIS',
sqlExpression: 'StartDate',
label: 'StartDate',
expressionType: 'SQL',
isColumnReference: true,
},
]);
```
##########
superset-frontend/plugins/plugin-chart-table/test/buildQuery.test.ts:
##########
@@ -268,6 +268,69 @@ test('preserves semantic reference when a filter overrides
the chart grain', ()
]);
});
+test('applies grain to every temporal dimension and keeps the first axis
first', () => {
+ const grain = TimeGranularity.MONTH;
+ const customColumn: AdhocColumn = {
+ expressionType: 'SQL',
+ sqlExpression: 'year(created_at)',
+ label: 'created_year',
+ };
+ const query = buildQueryUncached({
+ ...basicFormData,
+ groupby: ['category', customColumn, 'EndDate', 'StartDate'],
+ metrics: ['count'],
+ time_grain_sqla: grain,
+ temporal_columns_lookup: { EndDate: true, StartDate: true },
+ }).queries[0];
+
+ expect(query.columns).toEqual([
+ {
+ timeGrain: grain,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'EndDate',
+ label: 'EndDate',
+ expressionType: 'SQL',
+ },
+ 'category',
+ customColumn,
+ {
+ timeGrain: grain,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'StartDate',
+ label: 'StartDate',
+ expressionType: 'SQL',
+ },
+ ]);
+});
+
+test('applies dashboard grain override to every temporal dimension', () => {
+ const query = buildQueryUncached({
+ ...basicFormData,
+ groupby: ['StartDate', 'EndDate'],
+ metrics: ['count'],
+ time_grain_sqla: TimeGranularity.DAY,
+ extra_form_data: { time_grain_sqla: TimeGranularity.MONTH },
+ temporal_columns_lookup: { StartDate: true, EndDate: true },
+ }).queries[0];
+
+ expect(query.columns).toEqual([
+ {
+ timeGrain: TimeGranularity.MONTH,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'StartDate',
+ label: 'StartDate',
+ expressionType: 'SQL',
+ },
+ {
+ timeGrain: TimeGranularity.MONTH,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'EndDate',
+ label: 'EndDate',
+ expressionType: 'SQL',
+ },
+ ]);
Review Comment:
Matching expectation update for the `isColumnReference: true` change.
```suggestion
expect(query.columns).toEqual([
{
timeGrain: TimeGranularity.MONTH,
columnType: 'BASE_AXIS',
sqlExpression: 'StartDate',
label: 'StartDate',
expressionType: 'SQL',
isColumnReference: true,
},
{
timeGrain: TimeGranularity.MONTH,
columnType: 'BASE_AXIS',
sqlExpression: 'EndDate',
label: 'EndDate',
expressionType: 'SQL',
isColumnReference: true,
},
]);
```
##########
superset-frontend/plugins/plugin-chart-table/test/buildQuery.test.ts:
##########
@@ -268,6 +268,69 @@ test('preserves semantic reference when a filter overrides
the chart grain', ()
]);
});
+test('applies grain to every temporal dimension and keeps the first axis
first', () => {
+ const grain = TimeGranularity.MONTH;
+ const customColumn: AdhocColumn = {
+ expressionType: 'SQL',
+ sqlExpression: 'year(created_at)',
+ label: 'created_year',
+ };
+ const query = buildQueryUncached({
+ ...basicFormData,
+ groupby: ['category', customColumn, 'EndDate', 'StartDate'],
+ metrics: ['count'],
+ time_grain_sqla: grain,
+ temporal_columns_lookup: { EndDate: true, StartDate: true },
+ }).queries[0];
+
+ expect(query.columns).toEqual([
+ {
+ timeGrain: grain,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'EndDate',
+ label: 'EndDate',
+ expressionType: 'SQL',
+ },
+ 'category',
+ customColumn,
+ {
+ timeGrain: grain,
+ columnType: 'BASE_AXIS',
+ sqlExpression: 'StartDate',
+ label: 'StartDate',
+ expressionType: 'SQL',
+ },
+ ]);
Review Comment:
Matching expectation update for the `isColumnReference: true` change.
```suggestion
expect(query.columns).toEqual([
{
timeGrain: grain,
columnType: 'BASE_AXIS',
sqlExpression: 'EndDate',
label: 'EndDate',
expressionType: 'SQL',
isColumnReference: true,
},
'category',
customColumn,
{
timeGrain: grain,
columnType: 'BASE_AXIS',
sqlExpression: 'StartDate',
label: 'StartDate',
expressionType: 'SQL',
isColumnReference: true,
},
]);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]