Skip to content

Commit

Permalink
chore: clean up mixed-timeseries chart (apache#1352)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Nov 17, 2021
1 parent 75a432d commit 8cc40b0
Showing 1 changed file with 4 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
buildQueryContext,
getMetricLabel,
QueryFormData,
QueryObject,
normalizeOrderBy,
} from '@superset-ui/core';
import { buildQueryContext, QueryFormData, QueryObject, normalizeOrderBy } from '@superset-ui/core';
import { pivotOperator } from '@superset-ui/chart-controls';

export default function buildQuery(formData: QueryFormData) {
const {
Expand Down Expand Up @@ -61,45 +56,19 @@ export default function buildQuery(formData: QueryFormData) {
};

const queryContextA = buildQueryContext(formData1, baseQueryObject => {
const metricLabels = (baseQueryObject.metrics || []).map(getMetricLabel);
const queryObjectA = {
...baseQueryObject,
is_timeseries: true,
post_processing: [
{
operation: 'pivot',
options: {
index: ['__timestamp'],
columns: formData1.columns || [],
// Create 'dummy' sum aggregates to assign cell values in pivot table
aggregates: Object.fromEntries(
metricLabels.map(metric => [metric, { operator: 'sum' }]),
),
},
},
],
post_processing: [pivotOperator(formData1, { ...baseQueryObject, is_timeseries: true })],
} as QueryObject;
return [normalizeOrderBy(queryObjectA)];
});

const queryContextB = buildQueryContext(formData2, baseQueryObject => {
const metricLabels = (baseQueryObject.metrics || []).map(getMetricLabel);
const queryObjectB = {
...baseQueryObject,
is_timeseries: true,
post_processing: [
{
operation: 'pivot',
options: {
index: ['__timestamp'],
columns: formData2.columns || [],
// Create 'dummy' sum aggregates to assign cell values in pivot table
aggregates: Object.fromEntries(
metricLabels.map(metric => [metric, { operator: 'sum' }]),
),
},
},
],
post_processing: [pivotOperator(formData2, { ...baseQueryObject, is_timeseries: true })],
} as QueryObject;
return [normalizeOrderBy(queryObjectB)];
});
Expand Down

0 comments on commit 8cc40b0

Please sign in to comment.