Skip to content

Conversation

@bpintea
Copy link
Contributor

@bpintea bpintea commented Oct 20, 2025

This fixes the incorrect ordering of the columns that can occur when INLINE STATS is pruned entirely, due to its calculated value being discarded (overshadowed).

Fixes #136797

This fixes the incorrect ordering of the columns that can occur when INLINE STATS is pruned entirely, due to its calculated value being discarded (dropped or overshadowned)
@bpintea bpintea requested a review from astefan October 20, 2025 16:21
@bpintea bpintea added auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v9.2.1 v9.3.0 labels Oct 20, 2025
@bpintea bpintea marked this pull request as ready for review October 21, 2025 17:18
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Oct 21, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@bpintea bpintea added the >bug label Oct 22, 2025
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM. Left some minor comments, except the one with projection.

Also, I would add some variations to stats computations keepers and droppers:

ROW a = null, b = 0, c = "x", d = 1 | INLINE STATS a = MAX(c), d = MIN(c), e = AVG(b) by b | EVAL a = c, d = 2 ROW a = null, b = 0, c = "x", d = 1 | INLINE STATS a = MAX(c), d = MIN(c), e = AVG(b), a = MIN(b) by b | EVAL a = c, d = 2 ROW a = null, b = 0, c = "x", d = 1 | INLINE STATS a = MAX(c), d = MIN(c), e = AVG(b), a = MIN(b), f = MAX(b) by b | EVAL a = c, d = 2 
/**
* Fix pruning of columns when shadowed in INLINE STATS
*/
INLINE_STATS_PRUNE_COLUMN_FIX(INLINESTATS_V11.enabled),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
INLINE_STATS_PRUNE_COLUMN_FIX(INLINESTATS_V11.enabled),
INLINE_STATS_PRUNE_COLUMN_FIX(INLINE_STATS.enabled),
List<Attribute> newOutput = new ArrayList<>(ij.output());
AttributeSet leftOutputSet = ij.left().outputSet();
newOutput.removeIf(attr -> leftOutputSet.contains(attr) == false);
p = new EsqlProject(ij.source(), ij.left(), newOutput);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
p = new EsqlProject(ij.source(), ij.left(), newOutput);
p = new Project(ij.source(), ij.left(), newOutput);
var right = pruneColumns(ij.right(), used, true);
if (right.output().isEmpty() || isLocalEmptyRelation(right)) {
p = ij.left();
// InlineJoin updates the order of the output, so even if the computation is dropped, the groups need to be pulled to the end
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is putting an emphasis on re-ordering of the output elements, but in reality it's filtering the output based on the elements which are not needed anymore. The ordering is the same, only that some elements are filtered out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've supplemented the comment.

@bpintea
Copy link
Contributor Author

bpintea commented Oct 23, 2025

Thanks, Andrei.

Also, I would add some variations to stats computations keepers and droppers:

I've added them, though with small completions, since all the computed values need to be overwritten -- only then does the bug show.

@bpintea bpintea added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Oct 23, 2025
@elasticsearchmachine elasticsearchmachine merged commit ffbf05c into elastic:main Oct 23, 2025
34 checks passed
@bpintea bpintea deleted the fix/136797 branch October 23, 2025 14:13
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.2 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 136827

fzowl pushed a commit to voyage-ai/elasticsearch that referenced this pull request Nov 3, 2025
This fixes the incorrect ordering of the columns that can occur when INLINE STATS is pruned entirely, due to its calculated value being discarded (overshadowed). Fixes elastic#136797
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) backport pending >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.2.1 v9.3.0

3 participants