Skip to content

Commit 161a1cd

Browse files
committed
Merge remote-tracking branch 'upstream/lucene_snapshot_10_2_1' into lucene_snapshot_10_2_1
2 parents f3114b8 + 8e5106f commit 161a1cd

File tree

5 files changed

+67
-2
lines changed

5 files changed

+67
-2
lines changed

docs/changelog/126397.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 126397
2+
summary: "ESQL: Preserve single aggregate when all attributes are pruned"
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 126392

x-pack/plugin/esql/qa/testFixtures/src/main/resources/eval.csv-spec

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,39 @@ foo:keyword
637637
;
638638

639639

640+
evalAfterAvgUsingSameName
641+
required_capability: remove_empty_attribute_in_merging_output
642+
from employees
643+
| stats avg = avg(salary)
644+
| eval avg = 12
645+
;
646+
647+
avg:integer
648+
12
649+
;
650+
651+
evalAfterStatsUsingSameName
652+
required_capability: remove_empty_attribute_in_merging_output
653+
from employees
654+
| stats count = count(emp_no), median = median(salary), top_salaries = TOP(salary, 3, "desc")
655+
| keep median, top_salaries
656+
| rename top_salaries as median
657+
| eval median = 12
658+
;
659+
660+
median:integer
661+
12
662+
;
663+
664+
evalAfterStatsUsingSameName2
665+
required_capability: remove_empty_attribute_in_merging_output
666+
ROW foo = [10, 11, 12]
667+
| mv_expand foo
668+
| stats sum = sum(foo), max = max(foo)
669+
| rename sum as max
670+
| eval max = 13
671+
;
672+
673+
max:integer
674+
13
675+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ public enum Cap {
412412
*/
413413
RENAME_SEQUENTIAL_PROCESSING,
414414

415+
/**
416+
* Support for removing empty attribute in merging output.
417+
* See <a href="https://github.com/elastic/elasticsearch/issues/126392"> ESQL: EVAL after STATS produces an empty column #126392 </a>
418+
*/
419+
REMOVE_EMPTY_ATTRIBUTE_IN_MERGING_OUTPUT,
420+
415421
/**
416422
* Fix for union-types when some indexes are missing the required field. Done in #111932.
417423
*/

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PruneColumns.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.compute.data.BlockUtils;
1212
import org.elasticsearch.index.IndexMode;
1313
import org.elasticsearch.xpack.esql.core.expression.AttributeSet;
14-
import org.elasticsearch.xpack.esql.core.expression.EmptyAttribute;
1514
import org.elasticsearch.xpack.esql.core.expression.Expressions;
1615
import org.elasticsearch.xpack.esql.core.expression.NamedExpression;
1716
import org.elasticsearch.xpack.esql.core.util.Holder;
@@ -77,7 +76,7 @@ public LogicalPlan apply(LogicalPlan plan) {
7776
if (aggregate.groupings().isEmpty()) {
7877
p = new LocalRelation(
7978
aggregate.source(),
80-
List.of(new EmptyAttribute(aggregate.source())),
79+
List.of(Expressions.attribute(aggregate.aggregates().getFirst())),
8180
LocalSupplier.of(
8281
new Block[] { BlockUtils.constantBlock(PlannerUtils.NON_BREAKING_BLOCK_FACTORY, null, 1) }
8382
)

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,24 @@ private static List<String> orderNames(TopN topN) {
27842784
return topN.order().stream().map(o -> as(o.child(), NamedExpression.class).name()).toList();
27852785
}
27862786

2787+
/**
2788+
* Expects
2789+
* Eval[[2[INTEGER] AS x]]
2790+
* \_Limit[1000[INTEGER],false]
2791+
* \_LocalRelation[[{e}#9],[ConstantNullBlock[positions=1]]]
2792+
*/
2793+
public void testEvalAfterStats() {
2794+
var plan = optimizedPlan("""
2795+
ROW foo = 1
2796+
| STATS x = max(foo)
2797+
| EVAL x = 2
2798+
""");
2799+
var eval = as(plan, Eval.class);
2800+
var limit = as(eval.child(), Limit.class);
2801+
var localRelation = as(limit.child(), LocalRelation.class);
2802+
assertThat(Expressions.names(eval.output()), contains("x"));
2803+
}
2804+
27872805
public void testCombineLimitWithOrderByThroughFilterAndEval() {
27882806
LogicalPlan plan = optimizedPlan("""
27892807
from test

0 commit comments

Comments
 (0)