You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by kg...@apache.org on 2023/02/02 13:06:39 UTC

[superset] branch master updated: fix(explore): Time comparison in Mixed Chart in GENERIC_CHART_AXES not working (#22945)

This is an automated email from the ASF dual-hosted git repository.

kgabryje pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ed7b3533bc fix(explore): Time comparison in Mixed Chart in GENERIC_CHART_AXES not working (#22945)
ed7b3533bc is described below

commit ed7b3533bcc119b2240a613ebc56ace33f1e1002
Author: Kamil Gabryjelski <ka...@gmail.com>
AuthorDate: Thu Feb 2 14:06:30 2023 +0100

    fix(explore): Time comparison in Mixed Chart in GENERIC_CHART_AXES not working (#22945)
---
 .../src/MixedTimeseries/buildQuery.ts              |  7 +--
 .../test/MixedTimeseries/buildQuery.test.ts        | 63 ++++++++++++++++++----
 2 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts
index 5b74e0aeb1..39cfec9125 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/buildQuery.ts
@@ -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,
diff --git a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
index 066b796b59..af23bd927f 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/buildQuery.test.ts
@@ -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
@@ -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(
@@ -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();
 });