Skip to content

Commit

Permalink
[KQL] Remove number parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Mar 4, 2021
1 parent a61e1dd commit ccf7f11
Showing 3 changed files with 21 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 18 additions & 19 deletions src/plugins/data/common/es_query/kuery/ast/ast.test.ts
Original file line number Diff line number Diff line change
@@ -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');
3 changes: 1 addition & 2 deletions src/plugins/data/common/es_query/kuery/ast/kuery.peg
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ccf7f11

Please sign in to comment.