Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Mar 4, 2023
1 parent 2ce33cd commit 36f1ae8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import {
getXAxisLabel,
} from '@superset-ui/core';
import { PostProcessingFactory } from './types';
import { extractExtraMetrics } from './utils';

export const pivotOperator: PostProcessingFactory<PostProcessingPivot> = (
formData,
queryObject,
) => {
const metricLabels = ensureIsArray(queryObject.metrics).map(getMetricLabel);
metricLabels.push(
...ensureIsArray(queryObject.extra_metrics).map(getMetricLabel),
);
const extraMetrics = extractExtraMetrics(formData);
metricLabels.push(...extraMetrics.map(getMetricLabel));
const xAxisLabel = getXAxisLabel(formData);
const columns = queryObject.series_columns || queryObject.columns;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,12 @@ test('pivot by x_axis with extra metrics', () => {
{
...formData,
x_axis: 'foo',
x_axis_sort: 'bar',
groupby: [],
timeseries_limit_metric: 'bar',
},
{
...queryObject,
extra_metrics: ['bar'],
series_columns: [],
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ export interface QueryObject
/** Free-form WHERE SQL: multiple clauses are concatenated by AND */
where?: string;

/** extra metrics that should not be used for series */
extra_metrics?: QueryFormMetric[];

/** Limit number of series */
series_columns?: QueryFormColumn[];
series_limit?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,8 @@ export default function buildQuery(formData: QueryFormData) {
formData,
baseQueryObject,
)
? timeComparePivotOperator(formData, {
...baseQueryObject,
extra_metrics,
})
: pivotOperator(formData, {
...baseQueryObject,
extra_metrics,
});
? timeComparePivotOperator(formData, baseQueryObject)
: pivotOperator(formData, baseQueryObject);

const columns = [
...(isXAxisSet(formData) ? ensureIsArray(getXAxisColumn(formData)) : []),
Expand Down Expand Up @@ -107,7 +101,7 @@ export default function buildQuery(formData: QueryFormData) {
resampleOperator(formData, baseQueryObject),
renameOperator(formData, baseQueryObject),
contributionOperator(formData, baseQueryObject),
sortOperator(formData, { ...baseQueryObject, extra_metrics }),
sortOperator(formData, baseQueryObject),
flattenOperator(formData, baseQueryObject),
// todo: move prophet before flatten
prophetOperator(formData, baseQueryObject),
Expand Down
8 changes: 0 additions & 8 deletions superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,14 +1042,6 @@ class Meta: # pylint: disable=too-few-public-methods
"`ChartDataAdhocMetricSchema` for the structure of ad-hoc metrics.",
allow_none=True,
)
extra_metrics = fields.List(
fields.Raw(),
description="Metrics that are intended to be used for other purposes"
"than series. Note that these need to be listed in the metrics property,"
"similarly to how series_columns also need to be listed in the columns"
"property.",
allow_none=True,
)
post_processing = fields.List(
fields.Nested(ChartDataPostProcessingOperationSchema, allow_none=True),
allow_none=True,
Expand Down

0 comments on commit 36f1ae8

Please sign in to comment.