[Vega] Replacing the 'interval' property should only happen for the date_histogram aggregation (#115001)

This commit is contained in:
Alexey Antonov 2021-10-15 12:01:42 +03:00 committed by GitHub
parent 00db6023e6
commit 0fa440abad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View file

@ -178,11 +178,23 @@ describe(`EsQueryParser.injectQueryContextVars`, () => {
);
test(
`%autointerval% = true`,
check({ interval: { '%autointerval%': true } }, { calendar_interval: `1h` }, ctxObj)
check(
{ date_histogram: { interval: { '%autointerval%': true } } },
{ date_histogram: { calendar_interval: `1h` } },
ctxObj
)
);
test(
`%autointerval% = 10`,
check({ interval: { '%autointerval%': 10 } }, { fixed_interval: `3h` }, ctxObj)
check(
{ date_histogram: { interval: { '%autointerval%': 10 } } },
{ date_histogram: { fixed_interval: `3h` } },
ctxObj
)
);
test(
`histogram with interval`,
check({ histogram: { interval: 1 } }, { histogram: { interval: 1 } }, ctxObj)
);
test(`%timefilter% = min`, check({ a: { '%timefilter%': 'min' } }, { a: rangeStart }));
test(`%timefilter% = max`, check({ a: { '%timefilter%': 'max' } }, { a: rangeEnd }));

View file

@ -235,7 +235,8 @@ export class EsQueryParser {
interval?: { '%autointerval%': true | number } | string;
}
>,
isQuery: boolean
isQuery: boolean,
key?: string
) {
if (obj && typeof obj === 'object') {
if (Array.isArray(obj)) {
@ -281,9 +282,8 @@ export class EsQueryParser {
if (!subObj || typeof obj !== 'object') continue;
// replace "interval" with ES acceptable fixed_interval / calendar_interval
if (prop === 'interval') {
if (prop === 'interval' && key === 'date_histogram') {
let intervalString: string;
if (typeof subObj === 'string') {
intervalString = subObj;
} else if (subObj[AUTOINTERVAL]) {
@ -322,7 +322,7 @@ export class EsQueryParser {
this._createRangeFilter(subObj);
continue;
case undefined:
this._injectContextVars(subObj, isQuery);
this._injectContextVars(subObj, isQuery, prop);
continue;
default:
throw new Error(