Skip to content

Commit ca45080

Browse files
dnhatnkanoshioucostinivancea
authored
[8.x] ESQL: Ensure non-zero row size in EstimatesRowSize (#122762) (#123959)
* ESQL: Ensure non-zero row size in `EstimatesRowSize` (#122762) Closes #121535 (cherry picked from commit 4d2cb53) * Removed getFirst() usages --------- Co-authored-by: kanoshiou <[email protected]> Co-authored-by: Costin Leau <[email protected]> Co-authored-by: Iván Cea Fontenla <[email protected]> Co-authored-by: Iván Cea Fontenla <[email protected]>
1 parent c9e825e commit ca45080

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

docs/changelog/122762.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 122762
2+
summary: "ESQL: Remove estimated row size assertion"
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 121535

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,28 @@ public void testFilterWithNullAndEval() {
613613
}
614614
}
615615

616+
public void testSortWithNull() {
617+
try (EsqlQueryResponse results = run("row a = null | sort a")) {
618+
logger.info(results);
619+
assertEquals(1, getValuesList(results).size());
620+
int countIndex = results.columns().indexOf(new ColumnInfoImpl("a", "null"));
621+
assertThat(results.columns().stream().map(ColumnInfo::name).toList(), contains("a"));
622+
assertThat(results.columns().stream().map(ColumnInfoImpl::type).toList(), contains(DataType.NULL));
623+
assertNull(getValuesList(results).get(0).get(countIndex));
624+
}
625+
}
626+
627+
public void testStatsByNull() {
628+
try (EsqlQueryResponse results = run("row a = null | stats by a")) {
629+
logger.info(results);
630+
assertEquals(1, getValuesList(results).size());
631+
int countIndex = results.columns().indexOf(new ColumnInfoImpl("a", "null"));
632+
assertThat(results.columns().stream().map(ColumnInfo::name).toList(), contains("a"));
633+
assertThat(results.columns().stream().map(ColumnInfoImpl::type).toList(), contains(DataType.NULL));
634+
assertNull(getValuesList(results).get(0).get(countIndex));
635+
}
636+
}
637+
616638
public void testStringLength() {
617639
try (EsqlQueryResponse results = run("from test | eval l = length(color)")) {
618640
logger.info(results);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/AggregateExec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public Integer estimatedRowSize() {
136136
public PhysicalPlan estimateRowSize(State state) {
137137
state.add(false, aggregates); // The groupings are contained within the aggregates
138138
int size = state.consumeAllFields(true);
139+
size = Math.max(size, 1);
139140
return Objects.equals(this.estimatedRowSize, size)
140141
? this
141142
: new AggregateExec(source(), child(), groupings, aggregates, mode, intermediateAttributes, size);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/TopNExec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public PhysicalPlan estimateRowSize(State state) {
101101
final boolean needsSortedDocIds = output.stream().anyMatch(a -> a.dataType() == DataType.DOC_DATA_TYPE);
102102
state.add(needsSortedDocIds, output);
103103
int size = state.consumeAllFields(true);
104+
size = Math.max(size, 1);
104105
return Objects.equals(this.estimatedRowSize, size) ? this : new TopNExec(source(), child(), order, limit, size);
105106
}
106107

0 commit comments

Comments
 (0)