-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 190311-infra-replace-metricsuiaggregation-in…
…-favor-of-estypesaggregationsaggregate
- Loading branch information
Showing
77 changed files
with
3,300 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/kbn-esql-ast/src/__tests__/ast_parser.columns.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getAstAndSyntaxErrors as parse } from '../ast_parser'; | ||
|
||
describe('Column Identifier Expressions', () => { | ||
it('can parse un-quoted identifiers', () => { | ||
const text = 'ROW a, b.c'; | ||
const { ast } = parse(text); | ||
|
||
expect(ast).toMatchObject([ | ||
{ | ||
type: 'command', | ||
args: [ | ||
{ | ||
type: 'column', | ||
parts: ['a'], | ||
}, | ||
{ | ||
type: 'column', | ||
parts: ['b', 'c'], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('can parse quoted identifiers', () => { | ||
const text = 'ROW `a`, `b`.c, `d`.`👍`.`123``123`'; | ||
const { ast } = parse(text); | ||
|
||
expect(ast).toMatchObject([ | ||
{ | ||
type: 'command', | ||
args: [ | ||
{ | ||
type: 'column', | ||
parts: ['a'], | ||
}, | ||
{ | ||
type: 'column', | ||
parts: ['b', 'c'], | ||
}, | ||
{ | ||
type: 'column', | ||
parts: ['d', '👍', '123`123'], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('can mix quoted and un-quoted identifiers', () => { | ||
const text = 'ROW part1.part2.`part``3️⃣`'; | ||
const { ast } = parse(text); | ||
|
||
expect(ast).toMatchObject([ | ||
{ | ||
type: 'command', | ||
args: [ | ||
{ | ||
type: 'column', | ||
parts: ['part1', 'part2', 'part`3️⃣'], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
it('in KEEP command', () => { | ||
const text = 'FROM a | KEEP a.b'; | ||
const { ast } = parse(text); | ||
|
||
expect(ast).toMatchObject([ | ||
{}, | ||
{ | ||
type: 'command', | ||
args: [ | ||
{ | ||
type: 'column', | ||
parts: ['a', 'b'], | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const isQuotedIdentifier = (text: string): boolean => { | ||
const firstChar = text[0]; | ||
const lastChar = text[text.length - 1]; | ||
|
||
return firstChar === '`' && lastChar === '`'; | ||
}; | ||
|
||
export const parseIdentifier = (text: string): string => { | ||
const isQuoted = isQuotedIdentifier(text); | ||
|
||
if (!isQuoted) { | ||
return text; | ||
} | ||
|
||
return text.slice(1, -1).replace(/``/g, '`'); | ||
}; | ||
|
||
export const regexUnquotedIdentifierPattern = /^([a-z\*_\@]{1})[a-z0-9_\*]*$/i; | ||
|
||
export const formatIdentifier = (text: string): string => { | ||
if (regexUnquotedIdentifierPattern.test(text)) { | ||
return text; | ||
} | ||
|
||
return `\`${text.replace(/`/g, '``')}\``; | ||
}; | ||
|
||
export const formatIdentifierParts = (parts: string[]): string => | ||
parts.map(formatIdentifier).join('.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.