Skip to content

Commit

Permalink
[ES|QL] remove quoted index name support (#182994)
Browse files Browse the repository at this point in the history
## Summary

The Kibana version of
elastic/elasticsearch#108431

Removes support for quoted index names. 

Valid:
`from my_index`

Invalid
`from "my_index"`

<img width="514" alt="Screenshot 2024-05-08 at 2 10 24 PM"
src="https://github.com/elastic/kibana/assets/315764/f76f9128-cc13-41df-b885-b1ec30fe7ca3">
<img width="711" alt="Screenshot 2024-05-08 at 2 10 17 PM"
src="https://github.com/elastic/kibana/assets/315764/651c0480-ddcd-4f2b-ba05-862b3ca8a402">
  • Loading branch information
drewdaemon committed May 9, 2024
1 parent ea4d2c3 commit 34502a9
Show file tree
Hide file tree
Showing 10 changed files with 1,222 additions and 2,611 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 @@ -211,10 +211,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.

790 changes: 394 additions & 396 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 @@ -118,7 +118,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.

281 changes: 135 additions & 146 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 */, 68 /* 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 [67 /* esql_parser.UNQUOTED_IDENTIFIER */, 74 /* 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

0 comments on commit 34502a9

Please sign in to comment.