Skip to content

ESQL: Keep DROP attributes when resolving field names #127009

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/127009.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 127009
summary: "ESQL: Keep `DROP` attributes when resolving field names"
area: ES|QL
type: bug
issues:
- 126418
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public abstract class GenerativeRestTest extends ESRestTestCase {
"token recognition error at: '``", // https://github.com/elastic/elasticsearch/issues/125870
"Unknown column \\[.*\\]", // https://github.com/elastic/elasticsearch/issues/126026
"optimized incorrectly due to missing references", // https://github.com/elastic/elasticsearch/issues/116781
"No matches found for pattern", // https://github.com/elastic/elasticsearch/issues/126418
"The incoming YAML document exceeds the limit:" // still to investigate, but it seems to be specific to the test framework
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,19 @@ Milky Way
Milky Way
Milky Way
;

dropAgainWithWildcardAfterEval
required_capability: drop_again_with_wildcard_after_eval
from languages
| eval language_code = 12, x = 13
| drop language_code
| drop language*
| keep x
| limit 3
;

x:integer
13
13
13
;
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,12 @@ public enum Cap {
*/
FIX_JOIN_MASKING_EVAL,

/**
* Support for keeping `DROP` attributes when resolving field names.
* see <a href="https://github.com/elastic/elasticsearch/issues/126418"> ES|QL: no matches for pattern #126418 </a>
*/
DROP_AGAIN_WITH_WILDCARD_AFTER_EVAL,

/**
* Support last_over_time aggregation that gets evaluated per time-series
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ static PreAnalysisResult fieldNames(LogicalPlan parsed, Set<String> enrichPolicy
p.forEachExpression(UnresolvedNamePattern.class, up -> {
var ua = new UnresolvedAttribute(up.source(), up.name());
referencesBuilder.add(ua);
if (p instanceof Keep) {
if (p instanceof Keep || p instanceof Drop) {
keepCommandRefsBuilder.add(ua);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,16 @@ public void testEnrichAndJoinMaskingEvalWh() {
| keep emp_no, language_name""", Set.of("emp_no", "language_name", "languages", "language_name.*", "languages.*", "emp_no.*"));
}

public void testDropAgainWithWildcardAfterEval() {
assertFieldNames("""
from employees
| eval full_name = 12
| drop full_name
| drop *name
| keep emp_no
""", Set.of("emp_no", "emp_no.*", "*name", "*name.*"));
}

private Set<String> fieldNames(String query, Set<String> enrichPolicyMatchFields) {
var preAnalysisResult = new EsqlSession.PreAnalysisResult(null);
return EsqlSession.fieldNames(parser.createStatement(query), enrichPolicyMatchFields, preAnalysisResult).fieldNames();
Expand Down
Loading