Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(table): Use extras in queries #30335

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ const buildQuery: BuildQuery<TableChartFormData> = (
(ownState.currentPage ?? 0) * (ownState.pageSize ?? 0);
}

if (!temporalColum) {
Antonio-RiveroMartnez marked this conversation as resolved.
Show resolved Hide resolved
// This query is using only textual columns, so it doesn't need time grain
Antonio-RiveroMartnez marked this conversation as resolved.
Show resolved Hide resolved
extras.time_grain_sqla = undefined;
}

let queryObject = {
...baseQueryObject,
columns,
extras: !isEmpty(timeOffsets) && !temporalColum ? {} : extras,
extras,
orderby,
metrics,
post_processing: postProcessing,
Expand Down Expand Up @@ -239,7 +244,6 @@ const buildQuery: BuildQuery<TableChartFormData> = (
row_limit: 0,
row_offset: 0,
post_processing: [],
extras: undefined, // we don't need time grain here
order_desc: undefined, // we don't need orderby stuff here,
orderby: undefined, // because this query will be used for get total aggregation.
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,66 @@ describe('plugin-chart-table', () => {
expressionType: 'SQL',
});
});
it('should include time_grain_sqla in extras if temporal colum is used and keep the rest', () => {
const { queries } = buildQuery({
...basicFormData,
time_grain_sqla: TimeGranularity.MONTH,
groupby: ['col1'],
query_mode: QueryMode.Aggregate,
temporal_columns_lookup: { col1: true },
show_totals: true,
metrics: ['aaa', 'aaa'],
adhoc_filters: [
{
expressionType: 'SQL',
sqlExpression: "status IN ('In Process')",
clause: 'WHERE',
subject: null,
operator: null,
comparator: null,
isExtra: false,
isNew: false,
datasourceWarning: false,
filterOptionName: 'filter_v8m9t9oq5re_ndzk6g5am7',
} as any,
],
});
// Extras in regular query
expect(queries[0].extras?.time_grain_sqla).toEqual(TimeGranularity.MONTH);
expect(queries[0].extras?.where).toEqual("(status IN ('In Process'))");
// Extras in summary query
expect(queries[1].extras?.time_grain_sqla).toEqual(TimeGranularity.MONTH);
expect(queries[1].extras?.where).toEqual("(status IN ('In Process'))");
});
it('should not include time_grain_sqla in extras if temporal colum is not used and keep the rest', () => {
const { queries } = buildQuery({
...basicFormData,
time_grain_sqla: TimeGranularity.MONTH,
groupby: ['col1'],
query_mode: QueryMode.Aggregate,
show_totals: true,
metrics: ['aaa', 'aaa'],
adhoc_filters: [
{
expressionType: 'SQL',
sqlExpression: "status IN ('In Process')",
clause: 'WHERE',
subject: null,
operator: null,
comparator: null,
isExtra: false,
isNew: false,
datasourceWarning: false,
filterOptionName: 'filter_v8m9t9oq5re_ndzk6g5am7',
} as any,
],
});
Antonio-RiveroMartnez marked this conversation as resolved.
Show resolved Hide resolved
// Extras in regular query
expect(queries[0].extras?.time_grain_sqla).toBeUndefined();
expect(queries[0].extras?.where).toEqual("(status IN ('In Process'))");
// Extras in summary query
expect(queries[1].extras?.time_grain_sqla).toBeUndefined();
expect(queries[1].extras?.where).toEqual("(status IN ('In Process'))");
});
});
});
Loading