feat: generate consistent QueryObject whether GenericAxis is enabled or disabled (#21519)

This commit is contained in:
Yongjie Zhao
2022-09-21 09:41:21 +08:00
committed by GitHub
parent 6644a84f79
commit 4d12e3709e
22 changed files with 474 additions and 65 deletions

View File

@@ -18,11 +18,12 @@
*/
import {
buildQueryContext,
DTTM_ALIAS,
ensureIsArray,
normalizeOrderBy,
PostProcessingPivot,
QueryFormData,
getXAxis,
isXAxisSet,
} from '@superset-ui/core';
import {
rollingWindowOperator,
@@ -38,8 +39,7 @@ import {
} from '@superset-ui/chart-controls';
export default function buildQuery(formData: QueryFormData) {
const { x_axis, groupby } = formData;
const is_timeseries = x_axis === DTTM_ALIAS || !x_axis;
const { groupby } = formData;
return buildQueryContext(formData, baseQueryObject => {
/* the `pivotOperatorInRuntime` determines how to pivot the dataframe returned from the raw query.
1. If it's a time compared query, there will return a pivoted dataframe that append time compared metrics. for instance:
@@ -66,18 +66,17 @@ export default function buildQuery(formData: QueryFormData) {
baseQueryObject,
)
? timeComparePivotOperator(formData, baseQueryObject)
: pivotOperator(formData, {
...baseQueryObject,
index: x_axis,
is_timeseries,
});
: pivotOperator(formData, baseQueryObject);
return [
{
...baseQueryObject,
columns: [...ensureIsArray(x_axis), ...ensureIsArray(groupby)],
columns: [
...(isXAxisSet(formData) ? ensureIsArray(getXAxis(formData)) : []),
...ensureIsArray(groupby),
],
series_columns: groupby,
is_timeseries,
...(isXAxisSet(formData) ? {} : { is_timeseries: true }),
// todo: move `normalizeOrderBy to extractQueryFields`
orderby: normalizeOrderBy(baseQueryObject).orderby,
time_offsets: isTimeComparison(formData, baseQueryObject)
@@ -92,10 +91,7 @@ export default function buildQuery(formData: QueryFormData) {
rollingWindowOperator(formData, baseQueryObject),
timeCompareOperator(formData, baseQueryObject),
resampleOperator(formData, baseQueryObject),
renameOperator(formData, {
...baseQueryObject,
is_timeseries,
}),
renameOperator(formData, baseQueryObject),
contributionOperator(formData, baseQueryObject),
flattenOperator(formData, baseQueryObject),
// todo: move prophet before flatten