Skip to content

Commit a6047ed

Browse files
committed
Update CHANGE_POINT parser
1 parent 01027bb commit a6047ed

2 files changed

Lines changed: 34 additions & 86 deletions

File tree

src/parser/__tests__/change_point.test.ts

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -220,63 +220,11 @@ describe('CHANGE_POINT command', () => {
220220
});
221221

222222
describe('configuration order', () => {
223-
it('parses AS before ON (reversed order)', () => {
223+
it('Throws error if AS is before ON (reversed order)', () => {
224224
const text = `FROM index | CHANGE_POINT value AS type, pvalue ON key`;
225225
const query = EsqlQuery.fromSrc(text);
226226

227-
expect(query.errors.length).toBe(0);
228-
expect(query.ast.commands[1]).toMatchObject({
229-
type: 'command',
230-
name: 'change_point',
231-
value: {
232-
type: 'column',
233-
name: 'value',
234-
},
235-
key: {
236-
type: 'column',
237-
name: 'key',
238-
},
239-
target: {
240-
type: {
241-
type: 'column',
242-
name: 'type',
243-
},
244-
pvalue: {
245-
type: 'column',
246-
name: 'pvalue',
247-
},
248-
},
249-
args: [
250-
{
251-
type: 'column',
252-
name: 'value',
253-
},
254-
{
255-
type: 'option',
256-
name: 'as',
257-
args: [
258-
{
259-
type: 'column',
260-
name: 'type',
261-
},
262-
{
263-
type: 'column',
264-
name: 'pvalue',
265-
},
266-
],
267-
},
268-
{
269-
type: 'option',
270-
name: 'on',
271-
args: [
272-
{
273-
type: 'column',
274-
name: 'key',
275-
},
276-
],
277-
},
278-
],
279-
});
227+
expect(query.errors.length).toBe(1);
280228
});
281229
});
282230

src/parser/core/cst_to_ast_converter.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,40 +1359,40 @@ export class CstToAstConverter {
13591359

13601360
command.args.push(value);
13611361

1362-
for (const configCtx of ctx.changePointConfiguration_list()) {
1363-
if (configCtx._key && configCtx._key.getText()) {
1364-
const key = this.toColumn(configCtx._key);
1365-
const option = Builder.option(
1366-
{
1367-
name: 'on',
1368-
args: [key],
1369-
},
1370-
{
1371-
location: getPosition(configCtx.ON().symbol, configCtx._key.stop),
1372-
}
1373-
);
1362+
if (ctx._key && ctx._key.getText()) {
1363+
const key = this.toColumn(ctx._key);
1364+
const option = Builder.option(
1365+
{
1366+
name: 'on',
1367+
args: [key],
1368+
},
1369+
{
1370+
location: getPosition(ctx.ON().symbol, ctx._key.stop),
1371+
}
1372+
);
13741373

1375-
command.key = key;
1376-
command.args.push(option);
1377-
} else if (configCtx._targetType && configCtx._targetPvalue) {
1378-
const type = this.toColumn(configCtx._targetType);
1379-
const pvalue = this.toColumn(configCtx._targetPvalue);
1380-
const option = Builder.option(
1381-
{
1382-
name: 'as',
1383-
args: [type, pvalue],
1384-
},
1385-
{
1386-
location: getPosition(configCtx.AS().symbol, configCtx._targetPvalue.stop),
1387-
}
1388-
);
1374+
command.key = key;
1375+
command.args.push(option);
1376+
}
13891377

1390-
command.target = {
1391-
type,
1392-
pvalue,
1393-
};
1394-
command.args.push(option);
1395-
}
1378+
if (ctx._targetType && ctx._targetPvalue) {
1379+
const type = this.toColumn(ctx._targetType);
1380+
const pvalue = this.toColumn(ctx._targetPvalue);
1381+
const option = Builder.option(
1382+
{
1383+
name: 'as',
1384+
args: [type, pvalue],
1385+
},
1386+
{
1387+
location: getPosition(ctx.AS().symbol, ctx._targetPvalue.stop),
1388+
}
1389+
);
1390+
1391+
command.target = {
1392+
type,
1393+
pvalue,
1394+
};
1395+
command.args.push(option);
13961396
}
13971397

13981398
return command;

0 commit comments

Comments
 (0)