mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[8.15] [ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212) (#187895)
# Backport This will backport the following commits from `main` to `8.15`: - [[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)](https://github.com/elastic/kibana/pull/187212) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Kibana Machine","email":"42973632+kibanamachine@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-07-09T17:18:50Z","message":"[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)\n\nRelated to https://github.com/elastic/elasticsearch/pull/108395. This PR\r\nupdates the ES|QL grammars (lexer and parser) to match the latest\r\nversion in Elasticsearch. The PR adds support for index names wrapped by\r\n`\"\"`, and triple quotes `\"\"\"index-name\"\"\"` to the ES|QL text editor and\r\nremoves backticks.\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 22\"\r\nsrc=\"4e93f503
-9053-42a6-99c5-beda7bb4ba4c\">\r\n\r\n\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 24 54\"\r\nsrc=\"eec6292c
-f3c0-49f0-9864-cb3e6717e7a7\">\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 03\"\r\nsrc=\"66dca108
-a535-4df7-b1c0-42705c7913dd\">\r\n\r\n---------\r\n\r\nCo-authored-by: Quynh Nguyen <quynh.nguyen@elastic.co>\r\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"5bc0c7865e11b9b699d282c488286779b344f0e6","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:ES|QL","Team:ESQL","v8.15.0","v8.16.0"],"title":"[ES|QL] Update grammars: change quoting from backtick to quote for index names","number":187212,"url":"https://github.com/elastic/kibana/pull/187212","mergeCommit":{"message":"[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)\n\nRelated to https://github.com/elastic/elasticsearch/pull/108395. This PR\r\nupdates the ES|QL grammars (lexer and parser) to match the latest\r\nversion in Elasticsearch. The PR adds support for index names wrapped by\r\n`\"\"`, and triple quotes `\"\"\"index-name\"\"\"` to the ES|QL text editor and\r\nremoves backticks.\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 22\"\r\nsrc=\"4e93f503
-9053-42a6-99c5-beda7bb4ba4c\">\r\n\r\n\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 24 54\"\r\nsrc=\"eec6292c
-f3c0-49f0-9864-cb3e6717e7a7\">\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 03\"\r\nsrc=\"66dca108
-a535-4df7-b1c0-42705c7913dd\">\r\n\r\n---------\r\n\r\nCo-authored-by: Quynh Nguyen <quynh.nguyen@elastic.co>\r\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"5bc0c7865e11b9b699d282c488286779b344f0e6"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/187212","number":187212,"mergeCommit":{"message":"[ES|QL] Update grammars: change quoting from backtick to quote for index names (#187212)\n\nRelated to https://github.com/elastic/elasticsearch/pull/108395. This PR\r\nupdates the ES|QL grammars (lexer and parser) to match the latest\r\nversion in Elasticsearch. The PR adds support for index names wrapped by\r\n`\"\"`, and triple quotes `\"\"\"index-name\"\"\"` to the ES|QL text editor and\r\nremoves backticks.\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 22\"\r\nsrc=\"4e93f503
-9053-42a6-99c5-beda7bb4ba4c\">\r\n\r\n\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 24 54\"\r\nsrc=\"eec6292c
-f3c0-49f0-9864-cb3e6717e7a7\">\r\n<img width=\"1392\" alt=\"Screenshot 2024-07-09 at 09 25 03\"\r\nsrc=\"66dca108
-a535-4df7-b1c0-42705c7913dd\">\r\n\r\n---------\r\n\r\nCo-authored-by: Quynh Nguyen <quynh.nguyen@elastic.co>\r\nCo-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>","sha":"5bc0c7865e11b9b699d282c488286779b344f0e6"}}]}] BACKPORT-->
This commit is contained in:
parent
208f33a426
commit
fa414ee7ec
18 changed files with 1652 additions and 1398 deletions
|
@ -60,6 +60,36 @@ describe('FROM', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('can parse FROM query with single quote or triple quote', () => {
|
||||
const text = '\tFROM "foo%" \t\t, """bar{{00-00}}""", \n baz';
|
||||
const { ast, errors } = parse(text);
|
||||
|
||||
expect(errors.length).toBe(0);
|
||||
expect(ast).toMatchObject([
|
||||
{
|
||||
type: 'command',
|
||||
name: 'from',
|
||||
args: [
|
||||
{
|
||||
type: 'source',
|
||||
name: 'foo%',
|
||||
sourceType: 'index',
|
||||
},
|
||||
{
|
||||
type: 'source',
|
||||
name: 'bar{{00-00}}',
|
||||
sourceType: 'index',
|
||||
},
|
||||
{
|
||||
type: 'source',
|
||||
name: 'baz',
|
||||
sourceType: 'index',
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('can parse FROM query with a single metadata column', () => {
|
||||
const text = 'from foo METADATA bar';
|
||||
const { ast, errors } = parse(text);
|
||||
|
|
|
@ -44,13 +44,15 @@ WS
|
|||
: [ \r\n\t]+ -> channel(HIDDEN)
|
||||
;
|
||||
|
||||
fragment INDEX_UNQUOTED_IDENTIFIER_PART
|
||||
: ~[=`|,[\]/ \t\r\n]
|
||||
| '/' ~[*/] // allow single / but not followed by another / or * which would start a comment
|
||||
// in 8.14 ` were not allowed
|
||||
// this has been relaxed in 8.15 since " is used for quoting
|
||||
fragment UNQUOTED_SOURCE_PART
|
||||
: ~[:"=|,[\]/ \t\r\n]
|
||||
| '/' ~[*/] // allow single / but not followed by another / or * which would start a comment -- used in index pattern date spec
|
||||
;
|
||||
|
||||
INDEX_UNQUOTED_IDENTIFIER
|
||||
: INDEX_UNQUOTED_IDENTIFIER_PART+
|
||||
UNQUOTED_SOURCE
|
||||
: UNQUOTED_SOURCE_PART+
|
||||
;
|
||||
|
||||
//
|
||||
|
@ -212,15 +214,13 @@ mode FROM_MODE;
|
|||
FROM_PIPE : PIPE -> type(PIPE), popMode;
|
||||
FROM_OPENING_BRACKET : OPENING_BRACKET -> type(OPENING_BRACKET);
|
||||
FROM_CLOSING_BRACKET : CLOSING_BRACKET -> type(CLOSING_BRACKET);
|
||||
FROM_COLON : COLON -> type(COLON);
|
||||
FROM_COMMA : COMMA -> type(COMMA);
|
||||
FROM_ASSIGN : ASSIGN -> type(ASSIGN);
|
||||
FROM_QUOTED_STRING : QUOTED_STRING -> type(QUOTED_STRING);
|
||||
|
||||
METADATA : 'metadata';
|
||||
|
||||
FROM_INDEX_UNQUOTED_IDENTIFIER
|
||||
: INDEX_UNQUOTED_IDENTIFIER -> type(INDEX_UNQUOTED_IDENTIFIER)
|
||||
;
|
||||
FROM_UNQUOTED_SOURCE : UNQUOTED_SOURCE -> type(UNQUOTED_SOURCE);
|
||||
FROM_QUOTED_SOURCE : QUOTED_STRING -> type(QUOTED_STRING);
|
||||
|
||||
FROM_LINE_COMMENT
|
||||
: LINE_COMMENT -> channel(HIDDEN)
|
||||
|
@ -311,10 +311,6 @@ ENRICH_POLICY_NAME
|
|||
: (ENRICH_POLICY_NAME_BODY+ COLON)? ENRICH_POLICY_NAME_BODY+
|
||||
;
|
||||
|
||||
ENRICH_QUOTED_IDENTIFIER
|
||||
: QUOTED_IDENTIFIER -> type(QUOTED_IDENTIFIER)
|
||||
;
|
||||
|
||||
ENRICH_MODE_UNQUOTED_VALUE
|
||||
: ENRICH_POLICY_NAME -> type(ENRICH_POLICY_NAME)
|
||||
;
|
||||
|
@ -331,7 +327,7 @@ ENRICH_WS
|
|||
: WS -> channel(HIDDEN)
|
||||
;
|
||||
|
||||
// submode for Enrich to allow different lexing between policy identifier (loose) and field identifiers
|
||||
// submode for Enrich to allow different lexing between policy source (loose) and field identifiers
|
||||
mode ENRICH_FIELD_MODE;
|
||||
ENRICH_FIELD_PIPE : PIPE -> type(PIPE), popMode, popMode;
|
||||
ENRICH_FIELD_ASSIGN : ASSIGN -> type(ASSIGN);
|
||||
|
@ -363,13 +359,13 @@ ENRICH_FIELD_WS
|
|||
// LOOKUP ON key
|
||||
mode LOOKUP_MODE;
|
||||
LOOKUP_PIPE : PIPE -> type(PIPE), popMode;
|
||||
LOOKUP_COLON : COLON -> type(COLON);
|
||||
LOOKUP_COMMA : COMMA -> type(COMMA);
|
||||
LOOKUP_DOT: DOT -> type(DOT);
|
||||
LOOKUP_ON : ON -> type(ON), pushMode(LOOKUP_FIELD_MODE);
|
||||
|
||||
LOOKUP_INDEX_UNQUOTED_IDENTIFIER
|
||||
: INDEX_UNQUOTED_IDENTIFIER -> type(INDEX_UNQUOTED_IDENTIFIER)
|
||||
;
|
||||
LOOKUP_UNQUOTED_SOURCE: UNQUOTED_SOURCE -> type(UNQUOTED_SOURCE);
|
||||
LOOKUP_QUOTED_SOURCE : QUOTED_STRING -> type(QUOTED_STRING);
|
||||
|
||||
LOOKUP_LINE_COMMENT
|
||||
: LINE_COMMENT -> channel(HIDDEN)
|
||||
|
@ -496,9 +492,8 @@ SETTING_WS
|
|||
mode METRICS_MODE;
|
||||
METRICS_PIPE : PIPE -> type(PIPE), popMode;
|
||||
|
||||
METRICS_INDEX_UNQUOTED_IDENTIFIER
|
||||
: INDEX_UNQUOTED_IDENTIFIER -> type(INDEX_UNQUOTED_IDENTIFIER), popMode, pushMode(CLOSING_METRICS_MODE)
|
||||
;
|
||||
METRICS_UNQUOTED_SOURCE: UNQUOTED_SOURCE -> type(UNQUOTED_SOURCE), popMode, pushMode(CLOSING_METRICS_MODE);
|
||||
METRICS_QUOTED_SOURCE : QUOTED_STRING -> type(QUOTED_STRING), popMode, pushMode(CLOSING_METRICS_MODE);
|
||||
|
||||
METRICS_LINE_COMMENT
|
||||
: LINE_COMMENT -> channel(HIDDEN)
|
||||
|
@ -515,6 +510,10 @@ METRICS_WS
|
|||
// TODO: remove this workaround mode - see https://github.com/elastic/elasticsearch/issues/108528
|
||||
mode CLOSING_METRICS_MODE;
|
||||
|
||||
CLOSING_METRICS_COLON
|
||||
: COLON -> type(COLON), popMode, pushMode(METRICS_MODE)
|
||||
;
|
||||
|
||||
CLOSING_METRICS_COMMA
|
||||
: COMMA -> type(COMMA), popMode, pushMode(METRICS_MODE)
|
||||
;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -22,7 +22,7 @@ UNKNOWN_CMD=21
|
|||
LINE_COMMENT=22
|
||||
MULTILINE_COMMENT=23
|
||||
WS=24
|
||||
INDEX_UNQUOTED_IDENTIFIER=25
|
||||
UNQUOTED_SOURCE=25
|
||||
EXPLAIN_WS=26
|
||||
EXPLAIN_LINE_COMMENT=27
|
||||
EXPLAIN_MULTILINE_COMMENT=28
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -115,11 +115,21 @@ field
|
|||
;
|
||||
|
||||
fromCommand
|
||||
: FROM indexIdentifier (COMMA indexIdentifier)* metadata?
|
||||
: FROM indexPattern (COMMA indexPattern)* metadata?
|
||||
;
|
||||
|
||||
indexIdentifier
|
||||
: INDEX_UNQUOTED_IDENTIFIER
|
||||
indexPattern
|
||||
: clusterString COLON indexString
|
||||
| indexString
|
||||
;
|
||||
|
||||
clusterString
|
||||
: UNQUOTED_SOURCE
|
||||
;
|
||||
|
||||
indexString
|
||||
: UNQUOTED_SOURCE
|
||||
| QUOTED_STRING
|
||||
;
|
||||
|
||||
metadata
|
||||
|
@ -128,7 +138,7 @@ metadata
|
|||
;
|
||||
|
||||
metadataOption
|
||||
: METADATA indexIdentifier (COMMA indexIdentifier)*
|
||||
: METADATA UNQUOTED_SOURCE (COMMA UNQUOTED_SOURCE)*
|
||||
;
|
||||
|
||||
deprecated_metadata
|
||||
|
@ -136,7 +146,7 @@ deprecated_metadata
|
|||
;
|
||||
|
||||
metricsCommand
|
||||
: METRICS indexIdentifier (COMMA indexIdentifier)* aggregates=fields? (BY grouping=fields)?
|
||||
: METRICS indexPattern (COMMA indexPattern)* aggregates=fields? (BY grouping=fields)?
|
||||
;
|
||||
|
||||
evalCommand
|
||||
|
@ -289,5 +299,5 @@ enrichWithClause
|
|||
;
|
||||
|
||||
lookupCommand
|
||||
: LOOKUP tableName=INDEX_UNQUOTED_IDENTIFIER ON matchFields=qualifiedNamePatterns
|
||||
: LOOKUP tableName=indexPattern ON matchFields=qualifiedNamePatterns
|
||||
;
|
File diff suppressed because one or more lines are too long
|
@ -22,7 +22,7 @@ UNKNOWN_CMD=21
|
|||
LINE_COMMENT=22
|
||||
MULTILINE_COMMENT=23
|
||||
WS=24
|
||||
INDEX_UNQUOTED_IDENTIFIER=25
|
||||
UNQUOTED_SOURCE=25
|
||||
EXPLAIN_WS=26
|
||||
EXPLAIN_LINE_COMMENT=27
|
||||
EXPLAIN_MULTILINE_COMMENT=28
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,7 +33,9 @@ import { RowCommandContext } from "./esql_parser";
|
|||
import { FieldsContext } from "./esql_parser";
|
||||
import { FieldContext } from "./esql_parser";
|
||||
import { FromCommandContext } from "./esql_parser";
|
||||
import { IndexIdentifierContext } from "./esql_parser";
|
||||
import { IndexPatternContext } from "./esql_parser";
|
||||
import { ClusterStringContext } from "./esql_parser";
|
||||
import { IndexStringContext } from "./esql_parser";
|
||||
import { MetadataContext } from "./esql_parser";
|
||||
import { MetadataOptionContext } from "./esql_parser";
|
||||
import { Deprecated_metadataContext } from "./esql_parser";
|
||||
|
@ -419,15 +421,35 @@ export default class esql_parserListener extends ParseTreeListener {
|
|||
*/
|
||||
exitFromCommand?: (ctx: FromCommandContext) => void;
|
||||
/**
|
||||
* Enter a parse tree produced by `esql_parser.indexIdentifier`.
|
||||
* Enter a parse tree produced by `esql_parser.indexPattern`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
enterIndexIdentifier?: (ctx: IndexIdentifierContext) => void;
|
||||
enterIndexPattern?: (ctx: IndexPatternContext) => void;
|
||||
/**
|
||||
* Exit a parse tree produced by `esql_parser.indexIdentifier`.
|
||||
* Exit a parse tree produced by `esql_parser.indexPattern`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
exitIndexIdentifier?: (ctx: IndexIdentifierContext) => void;
|
||||
exitIndexPattern?: (ctx: IndexPatternContext) => void;
|
||||
/**
|
||||
* Enter a parse tree produced by `esql_parser.clusterString`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
enterClusterString?: (ctx: ClusterStringContext) => void;
|
||||
/**
|
||||
* Exit a parse tree produced by `esql_parser.clusterString`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
exitClusterString?: (ctx: ClusterStringContext) => void;
|
||||
/**
|
||||
* Enter a parse tree produced by `esql_parser.indexString`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
enterIndexString?: (ctx: IndexStringContext) => void;
|
||||
/**
|
||||
* Exit a parse tree produced by `esql_parser.indexString`.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
exitIndexString?: (ctx: IndexStringContext) => void;
|
||||
/**
|
||||
* Enter a parse tree produced by `esql_parser.metadata`.
|
||||
* @param ctx the parse tree
|
||||
|
|
|
@ -29,7 +29,7 @@ import {
|
|||
default as esql_parser,
|
||||
type MetaCommandContext,
|
||||
type MetricsCommandContext,
|
||||
IndexIdentifierContext,
|
||||
IndexPatternContext,
|
||||
} from './antlr/esql_parser';
|
||||
import { default as ESQLParserListener } from './antlr/esql_parser_listener';
|
||||
import {
|
||||
|
@ -154,7 +154,7 @@ export class AstListener implements ESQLParserListener {
|
|||
type: 'command',
|
||||
args: [],
|
||||
sources: ctx
|
||||
.getTypedRuleContexts(IndexIdentifierContext)
|
||||
.getTypedRuleContexts(IndexPatternContext)
|
||||
.map((sourceCtx) => createSource(sourceCtx)),
|
||||
};
|
||||
this.ast.push(node);
|
||||
|
|
|
@ -275,12 +275,24 @@ function safeBackticksRemoval(text: string | undefined) {
|
|||
return text?.replace(TICKS_REGEX, '').replace(DOUBLE_TICKS_REGEX, SINGLE_BACKTICK) || '';
|
||||
}
|
||||
|
||||
function sanitizeSourceString(ctx: ParserRuleContext) {
|
||||
const contextText = ctx.getText();
|
||||
// If wrapped by triple quote, remove
|
||||
if (contextText.startsWith(`"""`) && contextText.endsWith(`"""`)) {
|
||||
return contextText.replace(/\"\"\"/g, '');
|
||||
}
|
||||
// If wrapped by single quote, remove
|
||||
if (contextText.startsWith(`"`) && contextText.endsWith(`"`)) {
|
||||
return contextText.slice(1, -1);
|
||||
}
|
||||
return contextText;
|
||||
}
|
||||
|
||||
export function sanitizeIdentifierString(ctx: ParserRuleContext) {
|
||||
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
|
||||
|
||||
// TODO - understand why <missing null> is now returned as the match text for the FROM command
|
||||
return result === '<missing null>' ? '' : result;
|
||||
}
|
||||
|
@ -321,7 +333,7 @@ export function createSource(
|
|||
ctx: ParserRuleContext,
|
||||
type: 'index' | 'policy' = 'index'
|
||||
): ESQLSource {
|
||||
const text = sanitizeIdentifierString(ctx);
|
||||
const text = sanitizeSourceString(ctx);
|
||||
return {
|
||||
type: 'source',
|
||||
name: text,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { type ParserRuleContext } from 'antlr4';
|
||||
import { ParserRuleContext, TerminalNode } from 'antlr4';
|
||||
import {
|
||||
default as esql_parser,
|
||||
ArithmeticBinaryContext,
|
||||
|
@ -57,10 +57,10 @@ import {
|
|||
StringLiteralContext,
|
||||
type ValueExpressionContext,
|
||||
ValueExpressionDefaultContext,
|
||||
IndexIdentifierContext,
|
||||
InlineCastContext,
|
||||
InputNamedOrPositionalParamContext,
|
||||
InputParamContext,
|
||||
IndexPatternContext,
|
||||
} from './antlr/esql_parser';
|
||||
import {
|
||||
createSource,
|
||||
|
@ -98,16 +98,27 @@ import type {
|
|||
} from './types';
|
||||
|
||||
export function collectAllSourceIdentifiers(ctx: FromCommandContext): ESQLAstItem[] {
|
||||
const fromContexts = ctx.getTypedRuleContexts(IndexIdentifierContext);
|
||||
|
||||
const fromContexts = ctx.getTypedRuleContexts(IndexPatternContext);
|
||||
return fromContexts.map((sourceCtx) => createSource(sourceCtx));
|
||||
}
|
||||
|
||||
function terminalNodeToParserRuleContext(node: TerminalNode): ParserRuleContext {
|
||||
const context = new ParserRuleContext();
|
||||
context.start = node.symbol;
|
||||
context.stop = node.symbol;
|
||||
context.children = [node];
|
||||
return context;
|
||||
}
|
||||
function extractIdentifiers(
|
||||
ctx: KeepCommandContext | DropCommandContext | MvExpandCommandContext | MetadataOptionContext
|
||||
) {
|
||||
if (ctx instanceof MetadataOptionContext) {
|
||||
return wrapIdentifierAsArray(ctx.indexIdentifier_list());
|
||||
return ctx
|
||||
.UNQUOTED_SOURCE_list()
|
||||
.map((node) => {
|
||||
return terminalNodeToParserRuleContext(node);
|
||||
})
|
||||
.flat();
|
||||
}
|
||||
if (ctx instanceof MvExpandCommandContext) {
|
||||
return wrapIdentifierAsArray(ctx.qualifiedName());
|
||||
|
|
|
@ -64,6 +64,12 @@ describe('esql query helpers', () => {
|
|||
'METRICS pods load=avg(cpu), writes=max(rate(indexing_requests)) BY pod | SORT pod'
|
||||
);
|
||||
expect(idxPattern16).toBe('pods');
|
||||
|
||||
const idxPattern17 = getIndexPatternFromESQLQuery('FROM "$foo%"');
|
||||
expect(idxPattern17).toBe('$foo%');
|
||||
|
||||
const idxPattern18 = getIndexPatternFromESQLQuery('FROM """foo-{{mm-dd_yy}}"""');
|
||||
expect(idxPattern18).toBe('foo-{{mm-dd_yy}}');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ export const validationFromCommandTestSuite = (setup: helpers.Setup) => {
|
|||
"SyntaxError: mismatched input 'f' expecting {'explain', 'from', 'meta', 'metrics', 'row', 'show'}",
|
||||
]);
|
||||
await expectErrors('from ', [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'",
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}",
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -30,6 +30,8 @@ export const validationFromCommandTestSuite = (setup: helpers.Setup) => {
|
|||
|
||||
await expectErrors('from index', []);
|
||||
await expectErrors('FROM index', []);
|
||||
await expectErrors('FROM "index"', []);
|
||||
await expectErrors('FROM """index"""', []);
|
||||
await expectErrors('FrOm index', []);
|
||||
await expectErrors('from index, other_index', []);
|
||||
await expectErrors('from index, other_index,.secret_index', []);
|
||||
|
@ -65,10 +67,10 @@ export const validationFromCommandTestSuite = (setup: helpers.Setup) => {
|
|||
const { expectErrors } = await setup();
|
||||
|
||||
await expectErrors('from index,', [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'",
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}",
|
||||
]);
|
||||
await expectErrors(`FROM index\n, \tother_index\t,\n \t `, [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'",
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}",
|
||||
]);
|
||||
|
||||
await expectErrors(`from assignment = 1`, [
|
||||
|
@ -80,10 +82,7 @@ export const validationFromCommandTestSuite = (setup: helpers.Setup) => {
|
|||
test('errors on invalid syntax', async () => {
|
||||
const { expectErrors } = await setup();
|
||||
|
||||
await expectErrors('FROM `index`', [
|
||||
"SyntaxError: token recognition error at: '`'",
|
||||
"SyntaxError: token recognition error at: '`'",
|
||||
]);
|
||||
await expectErrors('FROM `index`', ['Unknown index [`index`]']);
|
||||
await expectErrors(`from assignment = 1`, [
|
||||
"SyntaxError: mismatched input '=' expecting <EOF>",
|
||||
'Unknown index [assignment]',
|
||||
|
|
|
@ -19,7 +19,7 @@ export const validationMetricsCommandTestSuite = (setup: helpers.Setup) => {
|
|||
"SyntaxError: mismatched input 'm' expecting {'explain', 'from', 'meta', 'metrics', 'row', 'show'}",
|
||||
]);
|
||||
await expectErrors('metrics ', [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'",
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}",
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -61,10 +61,10 @@ export const validationMetricsCommandTestSuite = (setup: helpers.Setup) => {
|
|||
const { expectErrors } = await setup();
|
||||
|
||||
await expectErrors('metrics index,', [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'",
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}",
|
||||
]);
|
||||
await expectErrors(`metrics index\n, \tother_index\t,\n \t `, [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'",
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}",
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -75,10 +75,7 @@ export const validationMetricsCommandTestSuite = (setup: helpers.Setup) => {
|
|||
"SyntaxError: token recognition error at: '='",
|
||||
"SyntaxError: token recognition error at: '1'",
|
||||
]);
|
||||
await expectErrors('metrics `index`', [
|
||||
"SyntaxError: token recognition error at: '`'",
|
||||
"SyntaxError: token recognition error at: '`'",
|
||||
]);
|
||||
await expectErrors('metrics `index`', ['Unknown index [`index`]']);
|
||||
});
|
||||
|
||||
test('errors on unknown index', async () => {
|
||||
|
|
|
@ -8662,7 +8662,8 @@
|
|||
{
|
||||
"query": "from a_index | enrich `this``is fine`",
|
||||
"error": [
|
||||
"SyntaxError: mismatched input '`this``is fine`' expecting ENRICH_POLICY_NAME"
|
||||
"SyntaxError: extraneous input 'fine`' expecting <EOF>",
|
||||
"Unknown policy [`this``is]"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
|
@ -26377,7 +26378,7 @@
|
|||
{
|
||||
"query": "from ",
|
||||
"error": [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'"
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
|
@ -26391,6 +26392,16 @@
|
|||
"error": [],
|
||||
"warning": []
|
||||
},
|
||||
{
|
||||
"query": "FROM \"index\"",
|
||||
"error": [],
|
||||
"warning": []
|
||||
},
|
||||
{
|
||||
"query": "FROM \"\"\"index\"\"\"",
|
||||
"error": [],
|
||||
"warning": []
|
||||
},
|
||||
{
|
||||
"query": "FrOm index",
|
||||
"error": [],
|
||||
|
@ -26539,14 +26550,14 @@
|
|||
{
|
||||
"query": "from index,",
|
||||
"error": [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'"
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
{
|
||||
"query": "FROM index\n, \tother_index\t,\n \t ",
|
||||
"error": [
|
||||
"SyntaxError: missing INDEX_UNQUOTED_IDENTIFIER at '<EOF>'"
|
||||
"SyntaxError: mismatched input '<EOF>' expecting {UNQUOTED_SOURCE, QUOTED_STRING}"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
|
@ -26561,8 +26572,7 @@
|
|||
{
|
||||
"query": "FROM `index`",
|
||||
"error": [
|
||||
"SyntaxError: token recognition error at: '`'",
|
||||
"SyntaxError: token recognition error at: '`'"
|
||||
"Unknown index [`index`]"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
|
|
|
@ -1359,7 +1359,8 @@ describe('validation logic', () => {
|
|||
]);
|
||||
testErrorsAndWarnings(`from a_index | enrich policy `, []);
|
||||
testErrorsAndWarnings('from a_index | enrich `this``is fine`', [
|
||||
"SyntaxError: mismatched input '`this``is fine`' expecting ENRICH_POLICY_NAME",
|
||||
"SyntaxError: extraneous input 'fine`' expecting <EOF>",
|
||||
'Unknown policy [`this``is]',
|
||||
]);
|
||||
testErrorsAndWarnings('from a_index | enrich this is fine', [
|
||||
"SyntaxError: mismatched input 'is' expecting <EOF>",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue