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(explore): Time comparison in Mixed Chart in GENERIC_CHART_AXES not working #22945

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -67,11 +67,8 @@ export default function buildQuery(formData: QueryFormData) {
fd,
queryObject,
)
? timeComparePivotOperator(fd, queryObject)
: pivotOperator(fd, {
...queryObject,
columns: fd.groupby,
});
? timeComparePivotOperator(fd, baseQueryObject)
: pivotOperator(fd, baseQueryObject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with using baseQueryObject is that it's the query builder's best guess as to what a single query query context would look like. In other words it will apply the same value to both queries, despite the fact that they should be separate. For this reason, we need to stick to whatever we have in queryObject, as that should already be rendered with the correct options. For this reason I'd actually propose the following change, which seems to work in all my quick test cases (only time compare on query A, only time compare on query B, and time compare on both queries):

Suggested change
? timeComparePivotOperator(fd, baseQueryObject)
: pivotOperator(fd, baseQueryObject);
? timeComparePivotOperator(fd, {
...queryObject,
columns: fd.groupby,
})
: pivotOperator(fd, {
...queryObject,
columns: fd.groupby,
});

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, done


const tmpQueryObject = {
...queryObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ test('should compile AA in query A', () => {
// time comparison
expect(query.time_offsets).toEqual(['1 years ago']);

// pivot
expect(
query.post_processing?.find(operator => operator?.operation === 'pivot'),
).toEqual({
operation: 'pivot',
options: {
index: ['__timestamp'],
columns: ['foo'],
drop_missing_columns: false,
aggregates: {
'sum(sales)': { operator: 'mean' },
'sum(sales)__1 years ago': { operator: 'mean' },
},
},
});
// cumsum
expect(
// prettier-ignore
Expand Down Expand Up @@ -384,20 +399,14 @@ test('should convert a queryObject with x-axis although FF is disabled', () => {
});

test("shouldn't convert a queryObject with axis although FF is enabled", () => {
let windowSpy: any;

beforeAll(() => {
const windowSpy = jest
.spyOn(window, 'window', 'get')
// @ts-ignore
windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(() => ({
.mockImplementation(() => ({
featureFlags: {
GENERIC_CHART_AXES: true,
},
}));
});

afterAll(() => {
windowSpy.mockRestore();
});

const { queries } = buildQuery(formDataMixedChart);
expect(queries[0]).toEqual(
Expand Down Expand Up @@ -468,4 +477,40 @@ test("shouldn't convert a queryObject with axis although FF is enabled", () => {
],
}),
);

windowSpy.mockRestore();
});

test('ensure correct pivot columns with GENERIC_CHART_AXES enabled', () => {
const windowSpy = jest
.spyOn(window, 'window', 'get')
// @ts-ignore
.mockImplementation(() => ({
featureFlags: {
GENERIC_CHART_AXES: true,
},
}));

const query = buildQuery({ ...formDataMixedChartWithAA, x_axis: 'ds' })
.queries[0];

expect(query.time_offsets).toEqual(['1 years ago']);

// pivot
expect(
query.post_processing?.find(operator => operator?.operation === 'pivot'),
).toEqual({
operation: 'pivot',
options: {
index: ['ds'],
columns: ['foo'],
drop_missing_columns: false,
aggregates: {
'sum(sales)': { operator: 'mean' },
'sum(sales)__1 years ago': { operator: 'mean' },
},
},
});

windowSpy.mockRestore();
});