mirror of
https://github.com/apache/superset.git
synced 2024-09-16 02:29:39 -04:00
fix: big number with trendline can't calculate cumsum (#19542)
This commit is contained in:
parent
c4baa826d5
commit
2daa071633
@ -18,63 +18,33 @@
|
|||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
buildQueryContext,
|
buildQueryContext,
|
||||||
PostProcessingResample,
|
DTTM_ALIAS,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
flattenOperator,
|
flattenOperator,
|
||||||
|
pivotOperator,
|
||||||
|
resampleOperator,
|
||||||
rollingWindowOperator,
|
rollingWindowOperator,
|
||||||
sortOperator,
|
|
||||||
} from '@superset-ui/chart-controls';
|
} from '@superset-ui/chart-controls';
|
||||||
|
|
||||||
const TIME_GRAIN_MAP: Record<string, string> = {
|
|
||||||
PT1S: 'S',
|
|
||||||
PT1M: 'min',
|
|
||||||
PT5M: '5min',
|
|
||||||
PT10M: '10min',
|
|
||||||
PT15M: '15min',
|
|
||||||
PT30M: '30min',
|
|
||||||
PT1H: 'H',
|
|
||||||
P1D: 'D',
|
|
||||||
P1M: 'MS',
|
|
||||||
P3M: 'QS',
|
|
||||||
P1Y: 'AS',
|
|
||||||
// TODO: these need to be mapped carefully, as the first day of week
|
|
||||||
// can vary from engine to engine
|
|
||||||
// P1W: 'W',
|
|
||||||
// '1969-12-28T00:00:00Z/P1W': 'W',
|
|
||||||
// '1969-12-29T00:00:00Z/P1W': 'W',
|
|
||||||
// 'P1W/1970-01-03T00:00:00Z': 'W',
|
|
||||||
// 'P1W/1970-01-04T00:00:00Z': 'W',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function buildQuery(formData: QueryFormData) {
|
export default function buildQuery(formData: QueryFormData) {
|
||||||
return buildQueryContext(formData, baseQueryObject => {
|
return buildQueryContext(formData, baseQueryObject => {
|
||||||
// todo: move into full advanced analysis section here
|
const { x_axis } = formData;
|
||||||
const rollingProc = rollingWindowOperator(formData, baseQueryObject);
|
const is_timeseries = x_axis === DTTM_ALIAS || !x_axis;
|
||||||
const { time_grain_sqla } = formData;
|
|
||||||
let resampleProc: PostProcessingResample;
|
|
||||||
if (rollingProc && time_grain_sqla) {
|
|
||||||
const rule = TIME_GRAIN_MAP[time_grain_sqla];
|
|
||||||
if (rule) {
|
|
||||||
resampleProc = {
|
|
||||||
operation: 'resample',
|
|
||||||
options: {
|
|
||||||
method: 'asfreq',
|
|
||||||
rule,
|
|
||||||
fill_value: null,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
...baseQueryObject,
|
...baseQueryObject,
|
||||||
is_timeseries: true,
|
is_timeseries: true,
|
||||||
post_processing: [
|
post_processing: [
|
||||||
sortOperator(formData, baseQueryObject),
|
pivotOperator(formData, {
|
||||||
resampleProc,
|
...baseQueryObject,
|
||||||
rollingProc,
|
index: x_axis,
|
||||||
|
is_timeseries,
|
||||||
|
}),
|
||||||
|
rollingWindowOperator(formData, baseQueryObject),
|
||||||
|
resampleOperator(formData, baseQueryObject),
|
||||||
flattenOperator(formData, baseQueryObject),
|
flattenOperator(formData, baseQueryObject),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -217,6 +217,52 @@ const config: ControlPanelConfig = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
// eslint-disable-next-line react/jsx-key
|
||||||
|
[<h1 className="section-header">{t('Resample')}</h1>],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: 'resample_rule',
|
||||||
|
config: {
|
||||||
|
type: 'SelectControl',
|
||||||
|
freeForm: true,
|
||||||
|
label: t('Rule'),
|
||||||
|
default: null,
|
||||||
|
choices: [
|
||||||
|
['1T', '1 minutely frequency'],
|
||||||
|
['1H', '1 hourly frequency'],
|
||||||
|
['1D', '1 calendar day frequency'],
|
||||||
|
['7D', '7 calendar day frequency'],
|
||||||
|
['1MS', '1 month start frequency'],
|
||||||
|
['1M', '1 month end frequency'],
|
||||||
|
['1AS', '1 year start frequency'],
|
||||||
|
['1A', '1 year end frequency'],
|
||||||
|
],
|
||||||
|
description: t('Pandas resample rule'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: 'resample_method',
|
||||||
|
config: {
|
||||||
|
type: 'SelectControl',
|
||||||
|
freeForm: true,
|
||||||
|
label: t('Fill method'),
|
||||||
|
default: null,
|
||||||
|
choices: [
|
||||||
|
['asfreq', 'Null imputation'],
|
||||||
|
['zerofill', 'Zero imputation'],
|
||||||
|
['linear', 'Linear interpolation'],
|
||||||
|
['ffill', 'Forward values'],
|
||||||
|
['bfill', 'Backward values'],
|
||||||
|
['median', 'Median values'],
|
||||||
|
['mean', 'Mean values'],
|
||||||
|
['sum', 'Sum values'],
|
||||||
|
],
|
||||||
|
description: t('Pandas resample method'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user