-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ES|QL: Improve field resolution for FORK #128501
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
Changes from 3 commits
f8f0478
1474874
40b9c7e
c2fa62f
2e83b97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -584,38 +584,17 @@ static PreAnalysisResult fieldNames(LogicalPlan parsed, Set<String> enrichPolicy | |
| return result.withFieldNames(IndexResolver.ALL_FIELDS); | ||
| } | ||
|
|
||
| Holder<Boolean> projectAll = new Holder<>(false); | ||
| parsed.forEachExpressionDown(UnresolvedStar.class, us -> {// explicit "*" fields selection | ||
| if (projectAll.get()) { | ||
| return; | ||
| } | ||
| projectAll.set(true); | ||
| }); | ||
|
|
||
| if (projectAll.get()) { | ||
| // TODO: Improve field resolution for FORK - right now we request all fields | ||
| if (parsed.anyMatch(p -> p instanceof Fork)) { | ||
| return result.withFieldNames(IndexResolver.ALL_FIELDS); | ||
| } | ||
|
|
||
| Holder<Boolean> projectAfterFork = new Holder<>(false); | ||
| Holder<Boolean> hasFork = new Holder<>(false); | ||
|
|
||
| parsed.forEachDown(plan -> { | ||
| Holder<Boolean> projectAll = new Holder<>(false); | ||
| parsed.forEachExpressionDown(UnresolvedStar.class, us -> {// explicit "*" fields selection | ||
| if (projectAll.get()) { | ||
| return; | ||
| } | ||
|
|
||
| if (hasFork.get() == false && shouldCollectReferencedFields(plan, inlinestatsAggs)) { | ||
| projectAfterFork.set(true); | ||
| } | ||
|
|
||
| if (plan instanceof Fork fork && projectAfterFork.get() == false) { | ||
| hasFork.set(true); | ||
| fork.children().forEach(child -> { | ||
| if (child.anyMatch(p -> shouldCollectReferencedFields(p, inlinestatsAggs)) == false) { | ||
| projectAll.set(true); | ||
| } | ||
| }); | ||
| } | ||
| projectAll.set(true); | ||
| }); | ||
|
|
||
| if (projectAll.get()) { | ||
|
|
@@ -637,6 +616,8 @@ static PreAnalysisResult fieldNames(LogicalPlan parsed, Set<String> enrichPolicy | |
|
|
||
| boolean[] canRemoveAliases = new boolean[] { true }; | ||
|
|
||
| PreAnalysisResult initialResult = result; | ||
| projectAll.set(false); | ||
| parsed.forEachDown(p -> {// go over each plan top-down | ||
| if (p instanceof RegexExtract re) { // for Grok and Dissect | ||
| // keep the inputs needed by Grok/Dissect | ||
|
|
@@ -711,6 +692,10 @@ static PreAnalysisResult fieldNames(LogicalPlan parsed, Set<String> enrichPolicy | |
| } | ||
| }); | ||
|
|
||
| if (projectAll.get()) { | ||
|
||
| return result.withFieldNames(IndexResolver.ALL_FIELDS); | ||
| } | ||
|
|
||
| // Add JOIN ON column references afterward to avoid Alias removal | ||
| referencesBuilder.addAll(keepJoinRefsBuilder); | ||
| // If any JOIN commands need wildcard field-caps calls, persist the index names | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1994,21 +1994,21 @@ public void testForkFieldsWithKeepAfterFork() { | |
| (WHERE d > 1000 AND e == "aaa" | EVAL c = a + 200) | ||
| | WHERE x > y | ||
| | KEEP a, b, c, d, x | ||
| """, Set.of("a", "a.*", "c", "c.*", "d", "d.*", "e", "e.*", "x", "x.*", "y", "y.*")); | ||
| """, ALL_FIELDS); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically here what we had before was better |
||
| } | ||
|
|
||
| public void testForkFieldsWithKeepBeforeFork() { | ||
| assumeTrue("FORK available as snapshot only", EsqlCapabilities.Cap.FORK.isEnabled()); | ||
|
|
||
| assertFieldNames(""" | ||
| FROM test | ||
| | KEEP a, b, c, d, x | ||
| | KEEP a, b, c, d, x, y | ||
| | WHERE a > 2000 | ||
| | EVAL b = a + 100 | ||
| | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500) | ||
| (WHERE d > 1000 AND e == "aaa" | EVAL c = a + 200) | ||
| | WHERE x > y | ||
| """, Set.of("a", "a.*", "b", "b.*", "c", "c.*", "d", "d.*", "e", "e.*", "x", "x.*", "y", "y.*")); | ||
| """, ALL_FIELDS); | ||
| } | ||
|
|
||
| public void testForkFieldsWithNoProjection() { | ||
|
|
@@ -2041,41 +2041,17 @@ public void testForkFieldsWithEnrichAndLookupJoins() { | |
| assumeTrue("FORK available as snapshot only", EsqlCapabilities.Cap.FORK.isEnabled()); | ||
| assumeTrue("LOOKUP JOIN available as snapshot only", EsqlCapabilities.Cap.JOIN_LOOKUP_V12.isEnabled()); | ||
|
|
||
| assertFieldNames( | ||
| """ | ||
| FROM test | ||
| | KEEP a, b, abc, def, z, xyz | ||
| | ENRICH enrich_policy ON abc | ||
| | EVAL b = a + 100 | ||
| | LOOKUP JOIN my_lookup_index ON def | ||
| | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500) | ||
| (STATS x = count(*), y=min(z)) | ||
| | LOOKUP JOIN my_lookup_index ON xyz | ||
| | WHERE x > y OR _fork == "fork1" | ||
| """, | ||
| Set.of( | ||
| "x", | ||
| "y", | ||
| "_fork", | ||
| "a", | ||
| "c", | ||
| "abc", | ||
| "b", | ||
| "def", | ||
| "z", | ||
| "xyz", | ||
| "def.*", | ||
| "_fork.*", | ||
| "y.*", | ||
| "x.*", | ||
| "xyz.*", | ||
| "z.*", | ||
| "abc.*", | ||
| "a.*", | ||
| "c.*", | ||
| "b.*" | ||
| ) | ||
| ); | ||
| assertFieldNames(""" | ||
| FROM test | ||
| | KEEP a, b, abc, def, z, xyz | ||
| | ENRICH enrich_policy ON abc | ||
| | EVAL b = a + 100 | ||
| | LOOKUP JOIN my_lookup_index ON def | ||
| | FORK (WHERE c > 1 AND a < 10000 | EVAL d = a + 500) | ||
| (STATS x = count(*), y=min(z)) | ||
| | LOOKUP JOIN my_lookup_index ON xyz | ||
| | WHERE x > y OR _fork == "fork1" | ||
| """, ALL_FIELDS); | ||
| } | ||
|
|
||
| public void testForkWithStatsInAllBranches() { | ||
|
|
@@ -2089,7 +2065,7 @@ public void testForkWithStatsInAllBranches() { | |
| (EVAL z = a * b | STATS m = max(z)) | ||
| (STATS x = count(*), y=min(z)) | ||
| | WHERE x > y | ||
| """, Set.of("a", "a.*", "b", "b.*", "c", "c.*", "z", "z.*")); | ||
| """, ALL_FIELDS); | ||
| } | ||
|
|
||
| public void testForkWithStatsAndWhere() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - I think this assignment is unnecessary