From ccf7f119983f00c6451138bc87059c60bf06166f Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 4 Mar 2021 11:12:41 -0700 Subject: [PATCH] [KQL] Remove number parsing --- .../es_query/kuery/ast/_generated_/kuery.js | 5 +-- .../common/es_query/kuery/ast/ast.test.ts | 37 +++++++++---------- .../data/common/es_query/kuery/ast/kuery.peg | 3 +- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js b/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js index fc6b706f6e01..aa77c3831be6 100644 --- a/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js +++ b/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js @@ -222,8 +222,7 @@ module.exports = (function() { if (sequence === 'true') return buildLiteralNode(true); if (sequence === 'false') return buildLiteralNode(false); if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence); - const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/ - return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence); + return buildLiteralNode(sequence); }, peg$c50 = { type: "any", description: "any character" }, peg$c51 = "*", @@ -3163,4 +3162,4 @@ module.exports = (function() { SyntaxError: peg$SyntaxError, parse: peg$parse }; -})(); +})(); \ No newline at end of file diff --git a/src/plugins/data/common/es_query/kuery/ast/ast.test.ts b/src/plugins/data/common/es_query/kuery/ast/ast.test.ts index 3a602cf102ff..930e7ba37ce3 100644 --- a/src/plugins/data/common/es_query/kuery/ast/ast.test.ts +++ b/src/plugins/data/common/es_query/kuery/ast/ast.test.ts @@ -150,10 +150,10 @@ describe('kuery AST API', () => { test('should support exclusive range operators', () => { const expected = nodeTypes.function.buildNode('and', [ nodeTypes.function.buildNode('range', 'bytes', { - gt: 1000, + gt: '1000', }), nodeTypes.function.buildNode('range', 'bytes', { - lt: 8000, + lt: '8000', }), ]); const actual = fromKueryExpression('bytes > 1000 and bytes < 8000'); @@ -163,10 +163,10 @@ describe('kuery AST API', () => { test('should support inclusive range operators', () => { const expected = nodeTypes.function.buildNode('and', [ nodeTypes.function.buildNode('range', 'bytes', { - gte: 1000, + gte: '1000', }), nodeTypes.function.buildNode('range', 'bytes', { - lte: 8000, + lte: '8000', }), ]); const actual = fromKueryExpression('bytes >= 1000 and bytes <= 8000'); @@ -261,25 +261,24 @@ describe('kuery AST API', () => { const stringLiteral = nodeTypes.literal.buildNode('foo'); const booleanFalseLiteral = nodeTypes.literal.buildNode(false); const booleanTrueLiteral = nodeTypes.literal.buildNode(true); - const numberLiteral = nodeTypes.literal.buildNode(42); expect(fromLiteralExpression('foo')).toEqual(stringLiteral); expect(fromLiteralExpression('true')).toEqual(booleanTrueLiteral); expect(fromLiteralExpression('false')).toEqual(booleanFalseLiteral); - expect(fromLiteralExpression('42')).toEqual(numberLiteral); - - expect(fromLiteralExpression('.3').value).toEqual(0.3); - expect(fromLiteralExpression('.36').value).toEqual(0.36); - expect(fromLiteralExpression('.00001').value).toEqual(0.00001); - expect(fromLiteralExpression('3').value).toEqual(3); - expect(fromLiteralExpression('-4').value).toEqual(-4); - expect(fromLiteralExpression('0').value).toEqual(0); - expect(fromLiteralExpression('0.0').value).toEqual(0); - expect(fromLiteralExpression('2.0').value).toEqual(2.0); - expect(fromLiteralExpression('0.8').value).toEqual(0.8); - expect(fromLiteralExpression('790.9').value).toEqual(790.9); - expect(fromLiteralExpression('0.0001').value).toEqual(0.0001); - expect(fromLiteralExpression('96565646732345').value).toEqual(96565646732345); + + expect(fromLiteralExpression('.3').value).toEqual('.3'); + expect(fromLiteralExpression('.36').value).toEqual('.36'); + expect(fromLiteralExpression('.00001').value).toEqual('.00001'); + expect(fromLiteralExpression('3').value).toEqual('3'); + expect(fromLiteralExpression('-4').value).toEqual('-4'); + expect(fromLiteralExpression('0').value).toEqual('0'); + expect(fromLiteralExpression('0.0').value).toEqual('0.0'); + expect(fromLiteralExpression('2.0').value).toEqual('2.0'); + expect(fromLiteralExpression('0.8').value).toEqual('0.8'); + expect(fromLiteralExpression('790.9').value).toEqual('790.9'); + expect(fromLiteralExpression('0.0001').value).toEqual('0.0001'); + expect(fromLiteralExpression('96565646732345').value).toEqual('96565646732345'); + expect(fromLiteralExpression('070').value).toEqual('070'); expect(fromLiteralExpression('..4').value).toEqual('..4'); expect(fromLiteralExpression('.3text').value).toEqual('.3text'); diff --git a/src/plugins/data/common/es_query/kuery/ast/kuery.peg b/src/plugins/data/common/es_query/kuery/ast/kuery.peg index 625c5069f936..1a31e7f75dc1 100644 --- a/src/plugins/data/common/es_query/kuery/ast/kuery.peg +++ b/src/plugins/data/common/es_query/kuery/ast/kuery.peg @@ -247,8 +247,7 @@ UnquotedLiteral if (sequence === 'true') return buildLiteralNode(true); if (sequence === 'false') return buildLiteralNode(false); if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence); - const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/ - return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence); + return buildLiteralNode(sequence); } UnquotedCharacter