From b476d2e126ae9da3503760fdfc2e2f4a8c4fe7d4 Mon Sep 17 00:00:00 2001 From: vadimkibana Date: Wed, 26 Mar 2025 18:22:10 +0100 Subject: [PATCH] deep check if change point on option has value --- .../src/parser/__tests__/change_point.test.ts | 29 +++++++++++++++++++ .../src/parser/factories/change_point.ts | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/change_point.test.ts b/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/change_point.test.ts index db493000012d7..03c20cd9644e8 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/change_point.test.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/change_point.test.ts @@ -220,4 +220,33 @@ describe('CHANGE_POINT command', () => { }); }); }); + + describe('incorrectly formatted', () => { + it('throws on missing ON arguments', () => { + const text = `FROM index | CHANGE_POINT value ON`; + const { errors, ast } = EsqlQuery.fromSrc(text); + const option = Walker.match(ast, { type: 'option', name: 'on' }); + + expect(errors.length).toBe(1); + expect(option).toBe(undefined); + }); + + it('throws on missing AS arguments', () => { + const text = `FROM index | CHANGE_POINT value AS`; + const { errors, ast } = EsqlQuery.fromSrc(text); + const option = Walker.match(ast, { type: 'option', name: 'as' }); + + expect(errors.length).toBe(1); + expect(option).toBe(undefined); + }); + + it('throws on missing AS arguments (ON present)', () => { + const text = `FROM index | CHANGE_POINT value ON a AS`; + const { errors, ast } = EsqlQuery.fromSrc(text); + const option = Walker.match(ast, { type: 'option', name: 'as' }); + + expect(errors.length).toBe(1); + expect(option).toBe(undefined); + }); + }); }); diff --git a/src/platform/packages/shared/kbn-esql-ast/src/parser/factories/change_point.ts b/src/platform/packages/shared/kbn-esql-ast/src/parser/factories/change_point.ts index 4b008aec8c03f..735604fa4f529 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/parser/factories/change_point.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/parser/factories/change_point.ts @@ -23,7 +23,7 @@ export const createChangePointCommand = ( command.args.push(value); - if (ctx._key) { + if (ctx._key && ctx._key.getText()) { const key = createColumn(ctx._key); const option = Builder.option( {