Skip to content

Commit 323b99c

Browse files
committed
feat: change point with aggregation
1 parent 35e8a1d commit 323b99c

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/parser/__tests__/change_point.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,27 @@ describe('CHANGE_POINT command', () => {
155155
});
156156
});
157157

158+
it('CHANGE_POINT with BY option (multiple fields)', () => {
159+
const text = `FROM index | CHANGE_POINT value BY category, long.field.name`;
160+
const query = EsqlQuery.fromSrc(text);
161+
162+
expect(query.ast.commands[1]).toMatchObject({
163+
type: 'command',
164+
name: 'change_point',
165+
args: [
166+
{ type: 'column', name: 'value' },
167+
{
168+
type: 'option',
169+
name: 'by',
170+
args: [
171+
{ type: 'column', name: 'category' },
172+
{ type: 'column', name: 'long.field.name' },
173+
],
174+
},
175+
],
176+
});
177+
});
178+
158179
it('parses example query with all options', () => {
159180
const text = `
160181
FROM k8s

src/parser/core/cst_to_ast_converter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,20 @@ export class CstToAstConverter {
13951395
command.args.push(option);
13961396
}
13971397

1398+
if (ctx.BY()) {
1399+
const booleanExpressions = (ctx._groupings ?? []).filter((e) => !e.exception);
1400+
const args = booleanExpressions.map((e) =>
1401+
this.fromBooleanExpressionToExpressionOrUnknown(e)
1402+
);
1403+
1404+
const byOption = this.toByOption(ctx, args);
1405+
1406+
if (byOption) {
1407+
command.args.push(byOption);
1408+
command.incomplete ||= byOption.incomplete;
1409+
}
1410+
}
1411+
13981412
return command;
13991413
};
14001414

0 commit comments

Comments
 (0)