Skip to content

ESQL: Remove duplicated nested commands #123085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 21, 2025

Conversation

costin
Copy link
Member

@costin costin commented Feb 21, 2025

Rework fork nested declaration to properly pop the mode stack otherwise, parsing gets stuck inside expression mode
and removed duplicated commands that caused lexing errors.

Without this fix, queries that previously were working such as: FROM index | STATS avg(max.limit) failed.

Relates to #121948

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Feb 21, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @costin, I've created a changelog YAML for you.

Fork grammar duplicated nested command declaration causing additional
 lexing to occur resulting in invalid field name declaration

Relates to elastic#121948
@costin costin force-pushed the esql/remove-nested-commands branch from 3fc4d36 to c5e5c67 Compare February 21, 2025 01:42
Comment on lines -226 to -227
NESTED_SORT : {this.isDevVersion()}? SORT -> type(SORT);
NESTED_LIMIT : {this.isDevVersion()}? LIMIT -> type(LIMIT);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These cause parsing error since commands don't need to be nested. WHERE is declared here for the STATS avg() WHERE declaration -WHERE inside a command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thank you.

@@ -678,8 +677,8 @@ INSIST_MULTILINE_COMMENT : MULTILINE_COMMENT -> channel(HIDDEN);
//
mode FORK_MODE;
FORK_LP : LP -> type(LP), pushMode(DEFAULT_MODE);
FORK_RP : RP -> type(RP), popMode;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The popup mode should already be completed by the sub fork, otherwise the mode stack is not completed, causing non-first subqueries to fail (since parsing is executed in a different mode).

@costin costin requested review from astefan, bpintea, ioanatia, ChrisHegarty and fang-xing-esql and removed request for bpintea February 21, 2025 01:45
@elasticsearchmachine
Copy link
Collaborator

Hi @costin, I've created a changelog YAML for you.

@@ -3085,7 +3085,28 @@ public void testInvalidFork() {
"line 1:20: mismatched input 'FORK' expecting {'limit', 'sort', 'where'}"
);
expectError("FROM foo* | FORK ( x+1 ) ( WHERE y>2 )", "line 1:20: mismatched input 'x+1' expecting {'limit', 'sort', 'where'}");
expectError("FROM foo* | FORK ( LIMIT 10 ) ( y+2 )", "line 1:33: mismatched input 'y' expecting {'limit', 'sort', 'where'}");
expectError("FROM foo* | FORK ( LIMIT 10 ) ( y+2 )", "line 1:33: mismatched input 'y+2' expecting {'limit', 'sort', 'where'}");
Copy link
Contributor

@ChrisHegarty ChrisHegarty Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I dunno why this escaped the CI testing in the PR that added the test scenario! ? (I'll check this separately)

pr: 123085
summary: Remove duplicated nested commands
area: ES|QL
type: bug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely a bug, but it should not escape into a published artifact or release.

Copy link
Contributor

@ChrisHegarty ChrisHegarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing. And apologies for breaking in the first place. LGTM

@ChrisHegarty
Copy link
Contributor

I updated the branch with main in order to pickup #122586 ( which I see causing failures in this PR )

@costin costin merged commit 21845ad into elastic:main Feb 21, 2025
17 checks passed
@costin costin deleted the esql/remove-nested-commands branch February 21, 2025 14:56
costin added a commit that referenced this pull request Mar 15, 2025
Due to recent grammar changes made ( token to no longer be reported by
 its text rather by his internal token name. Due to the use of pushMode,
 the symbol is not treated as a literal rather as a symbol.
To address this, the parser listener looks at the error message and
 changes the message before returning it to the user.

Replace hacky regex approach with Vocabulary substitution (not
 as pluggable as it could be yet much better)

Fix #124145
Relates #123085 #121948

Co-authored-by: Alexander Spies <alexander.spies@elastic.co>
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
Due to recent grammar changes made ( token to no longer be reported by
 its text rather by his internal token name. Due to the use of pushMode,
 the symbol is not treated as a literal rather as a symbol.
To address this, the parser listener looks at the error message and
 changes the message before returning it to the user.

Replace hacky regex approach with Vocabulary substitution (not
 as pluggable as it could be yet much better)

Fix elastic#124145
Relates elastic#123085 elastic#121948

Co-authored-by: Alexander Spies <alexander.spies@elastic.co>
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request May 1, 2025
Due to recent grammar changes made ( token to no longer be reported by
its text rather by his internal token name. Due to the use of pushMode,
the symbol is not treated as a literal rather as a symbol.
To address this, the parser listener looks at the error message and
changes the message before returning it to the user.

Fix elastic#124145
Relates elastic#123085 elastic#121948
nik9000 added a commit that referenced this pull request May 1, 2025
Due to recent grammar changes made ( token to no longer be reported by
its text rather by his internal token name. Due to the use of pushMode,
the symbol is not treated as a literal rather as a symbol.
To address this, the parser listener looks at the error message and
changes the message before returning it to the user.

Fix #124145
Relates #123085 #121948
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants