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(charts): Time grain is None when dataset uses Jinja #25842

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -70,10 +70,7 @@ export function normalizeTimeColumn(
};
}

const newQueryObject = omit(queryObject, [
'extras.time_grain_sqla',
'is_timeseries',
]);
const newQueryObject = omit(queryObject, ['is_timeseries']);
newQueryObject.columns = mutatedColumns;

return newQueryObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ describe('GENERIC_CHART_AXES is disabled', () => {
datasource: '5__table',
viz_type: 'table',
granularity: 'time_column',
extras: {},
extras: {
time_grain_sqla: 'P1Y',
},
time_range: '1 year ago : 2013',
orderby: [['count(*)', true]],
columns: [
Expand Down Expand Up @@ -182,7 +184,7 @@ describe('GENERIC_CHART_AXES is enabled', () => {
datasource: '5__table',
viz_type: 'table',
granularity: 'time_column',
extras: { where: '', having: '' },
extras: { where: '', having: '', time_grain_sqla: 'P1Y' },
time_range: '1 year ago : 2013',
orderby: [['count(*)', true]],
columns: [
Expand Down Expand Up @@ -240,7 +242,7 @@ describe('GENERIC_CHART_AXES is enabled', () => {
datasource: '5__table',
viz_type: 'table',
granularity: 'time_column',
extras: { where: '', having: '' },
extras: { where: '', having: '', time_grain_sqla: 'P1Y' },
time_range: '1 year ago : 2013',
orderby: [['count(*)', true]],
columns: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ test('should convert a queryObject with x-axis although FF is disabled', () => {
extras: {
having: '',
where: "(foo in ('a', 'b'))",
time_grain_sqla: 'P1W',
},
applied_time_extras: {},
columns: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('GENERIC_CHART_AXES is enabled', () => {
expect.objectContaining({
granularity: 'time_column',
time_range: '1 year ago : 2013',
extras: { having: '', where: '' },
extras: { having: '', where: '', time_grain_sqla: 'P1Y' },
columns: [
{
columnType: 'BASE_AXIS',
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('GENERIC_CHART_AXES is disabled', () => {
expect.objectContaining({
granularity: 'time_column',
time_range: '1 year ago : 2013',
extras: { having: '', where: '' },
extras: { having: '', where: '', time_grain_sqla: 'P1Y' },
columns: [
{
columnType: 'BASE_AXIS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import omit from 'lodash/omit';

import {
AdhocColumn,
buildQueryContext,
Expand Down Expand Up @@ -72,9 +70,7 @@ export default function buildQuery(formData: PivotTableQueryFormData) {
}
return [
{
...(hasGenericChartAxes
? omit(baseQueryObject, ['extras.time_grain_sqla'])
: baseQueryObject),
...baseQueryObject,
orderby: orderBy,
columns,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,16 @@ test('should fallback to formData.time_grain_sqla if extra_form_data.time_grain_
expressionType: 'SQL',
});
});

test('should not omit extras.time_grain_sqla from queryContext so dashboards apply them', () => {
Object.defineProperty(supersetCoreModule, 'hasGenericChartAxes', {
value: true,
});
const modifiedFormData = {
...formData,
extra_form_data: { time_grain_sqla: TimeGranularity.QUARTER },
};
const queryContext = buildQuery(modifiedFormData);
const [query] = queryContext.queries;
expect(query.extras?.time_grain_sqla).toEqual(TimeGranularity.QUARTER);
});
Loading