Skip to content

Commit

Permalink
Merge branch '8.14' into backport/8.14/pr-182605
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed May 9, 2024
2 parents cb25073 + 6a1a267 commit f5d05f5
Show file tree
Hide file tree
Showing 48 changed files with 5,187 additions and 1,193 deletions.
4 changes: 0 additions & 4 deletions packages/kbn-esql-ast/src/antlr/esql_lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ FROM_UNQUOTED_IDENTIFIER
: FROM_UNQUOTED_IDENTIFIER_PART+
;

FROM_QUOTED_IDENTIFIER
: QUOTED_IDENTIFIER -> type(QUOTED_IDENTIFIER)
;

FROM_LINE_COMMENT
: LINE_COMMENT -> channel(HIDDEN)
;
Expand Down
3 changes: 1 addition & 2 deletions packages/kbn-esql-ast/src/antlr/esql_lexer.interp

Large diffs are not rendered by default.

791 changes: 394 additions & 397 deletions packages/kbn-esql-ast/src/antlr/esql_lexer.ts

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/kbn-esql-ast/src/antlr/esql_parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ fromCommand

fromIdentifier
: FROM_UNQUOTED_IDENTIFIER
| QUOTED_IDENTIFIER
;

fromOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/antlr/esql_parser.interp

Large diffs are not rendered by default.

275 changes: 132 additions & 143 deletions packages/kbn-esql-ast/src/antlr/esql_parser.ts

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions packages/kbn-esql-ast/src/ast_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ export function computeLocationExtends(fn: ESQLFunction) {

/* SCRIPT_MARKER_START */
function getQuotedText(ctx: ParserRuleContext) {
return [67 /* esql_parser.QUOTED_IDENTIFIER */]
return [27 /* esql_parser.QUOTED_STRING */, 67 /* esql_parser.QUOTED_IDENTIFIER */]
.map((keyCode) => ctx.getToken(keyCode, 0))
.filter(nonNullable)[0];
}

function getUnquotedText(ctx: ParserRuleContext) {
return [66 /* esql_parser.UNQUOTED_IDENTIFIER */, 72 /* esql_parser.FROM_UNQUOTED_IDENTIFIER */]
return [66 /* esql_parser.UNQUOTED_IDENTIFIER */, 73 /* esql_parser.FROM_UNQUOTED_IDENTIFIER */]
.map((keyCode) => ctx.getToken(keyCode, 0))
.filter(nonNullable)[0];
}
Expand All @@ -238,11 +238,13 @@ function safeBackticksRemoval(text: string | undefined) {
}

export function sanitizeIdentifierString(ctx: ParserRuleContext) {
return (
const result =
getUnquotedText(ctx)?.getText() ||
safeBackticksRemoval(getQuotedText(ctx)?.getText()) ||
safeBackticksRemoval(ctx.getText()) // for some reason some quoted text is not detected correctly by the parser
);
safeBackticksRemoval(ctx.getText()); // for some reason some quoted text is not detected correctly by the parser

// TODO - understand why <missing null> is now returned as the match text for the FROM command
return result === '<missing null>' ? '' : result;
}

export function wrapIdentifierAsArray<T extends ParserRuleContext>(identifierCtx: T | T[]): T[] {
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-esql-ast/src/ast_walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ import type {
} from './types';

export function collectAllSourceIdentifiers(ctx: FromCommandContext): ESQLAstItem[] {
return ctx
.getTypedRuleContexts(FromIdentifierContext)
.map((sourceCtx) => createSource(sourceCtx));
const fromContexts = ctx.getTypedRuleContexts(FromIdentifierContext);

return fromContexts.map((sourceCtx) => createSource(sourceCtx));
}

function extractIdentifiers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,22 @@ function createComparisonDefinition(
],
returnType: 'boolean',
},
...['date', 'number'].flatMap((type) => [
{
params: [
{ name: 'left', type: 'version' },
{ name: 'right', type: 'version' },
],
returnType: 'boolean',
},
// constant strings okay because of implicit casting for
// string to version and ip
//
// boolean casting is handled on the specific comparison function
// that support booleans
//
// date casting is handled in the validation routine since it's a
// general rule. Look in compareLiteralType()
...['ip', 'version'].flatMap((type) => [
{
params: [
{ name: 'left', type },
Expand Down Expand Up @@ -214,6 +229,21 @@ export const builtinFunctions: FunctionDefinition[] = [
],
returnType: 'boolean',
},
// constant strings okay because of implicit casting
{
params: [
{ name: 'left', type: 'boolean' },
{ name: 'right', type: 'string', constantOnly: true },
],
returnType: 'boolean',
},
{
params: [
{ name: 'right', type: 'string', constantOnly: true },
{ name: 'right', type: 'boolean' },
],
returnType: 'boolean',
},
],
},
{
Expand All @@ -232,6 +262,21 @@ export const builtinFunctions: FunctionDefinition[] = [
],
returnType: 'boolean',
},
// constant strings okay because of implicit casting
{
params: [
{ name: 'left', type: 'boolean' },
{ name: 'right', type: 'string', constantOnly: true },
],
returnType: 'boolean',
},
{
params: [
{ name: 'right', type: 'string', constantOnly: true },
{ name: 'right', type: 'boolean' },
],
returnType: 'boolean',
},
],
},
{
Expand Down Expand Up @@ -318,6 +363,15 @@ export const builtinFunctions: FunctionDefinition[] = [
},
{ name: 'not_in', description: '' },
].map<FunctionDefinition>(({ name, description }) => ({
// set all arrays to type "any" for now
// this only applies to the "in" operator
// e.g. "foo" in ( "foo", "bar" )
//
// we did this because the "in" operator now supports
// mixed-type arrays like ( "1.2.3", versionVar )
// because of implicit casting.
//
// we need to revisit with more robust validation
type: 'builtin',
ignoreAsSuggestion: /not/.test(name),
name,
Expand All @@ -327,28 +381,43 @@ export const builtinFunctions: FunctionDefinition[] = [
{
params: [
{ name: 'left', type: 'number' },
{ name: 'right', type: 'number[]' },

{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'string' },
{ name: 'right', type: 'string[]' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'boolean' },
{ name: 'right', type: 'boolean[]' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'date' },
{ name: 'right', type: 'date[]' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'version' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
{
params: [
{ name: 'left', type: 'ip' },
{ name: 'right', type: 'any[]' },
],
returnType: 'boolean',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export const evalFunctionsDefinitions: FunctionDefinition[] = [
signatures: [
{
params: [{ name: 'field', type: 'string' }],
returnType: 'string',
returnType: 'version',
examples: [`from index | EVAL version = to_version(stringField)`],
},
],
Expand Down

0 comments on commit f5d05f5

Please sign in to comment.