Skip to content

Commit

Permalink
[Vega] Replacing the 'interval' property should only happen for the d…
Browse files Browse the repository at this point in the history
…ate_histogram aggregation
  • Loading branch information
alexwizp committed Oct 14, 2021
1 parent 3899046 commit daf9f3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit daf9f3b

Please sign in to comment.