Skip to content

Commit

Permalink
fix(explore): Time comparison in Mixed Chart in GENERIC_CHART_AXES no…
Browse files Browse the repository at this point in the history
…t working (apache#22945)
  • Loading branch information
kgabryje authored and PawankumarES committed Feb 13, 2023
1 parent ffbc800 commit e8656f0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
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, { ...queryObject, columns: fd.groupby })
: pivotOperator(fd, { ...queryObject, columns: fd.groupby });

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();
});

0 comments on commit e8656f0

Please sign in to comment.