Skip to content

Commit 8e409d6

Browse files
dnhatnkanoshiou
andauthored
ESQL: Ensure non-zero row size in EstimatesRowSize (#122762) (#123958)
Closes #121535 Co-authored-by: kanoshiou <[email protected]>
1 parent e540f86 commit 8e409d6

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

docs/changelog/122762.yaml

+6
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

+22
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,28 @@ public void testFilterWithNullAndEval() {
587587
}
588588
}
589589

590+
public void testSortWithNull() {
591+
try (EsqlQueryResponse results = run("row a = null | sort a")) {
592+
logger.info(results);
593+
assertEquals(1, getValuesList(results).size());
594+
int countIndex = results.columns().indexOf(new ColumnInfoImpl("a", "null"));
595+
assertThat(results.columns().stream().map(ColumnInfo::name).toList(), contains("a"));
596+
assertThat(results.columns().stream().map(ColumnInfoImpl::type).toList(), contains(DataType.NULL));
597+
assertNull(getValuesList(results).getFirst().get(countIndex));
598+
}
599+
}
600+
601+
public void testStatsByNull() {
602+
try (EsqlQueryResponse results = run("row a = null | stats by a")) {
603+
logger.info(results);
604+
assertEquals(1, getValuesList(results).size());
605+
int countIndex = results.columns().indexOf(new ColumnInfoImpl("a", "null"));
606+
assertThat(results.columns().stream().map(ColumnInfo::name).toList(), contains("a"));
607+
assertThat(results.columns().stream().map(ColumnInfoImpl::type).toList(), contains(DataType.NULL));
608+
assertNull(getValuesList(results).getFirst().get(countIndex));
609+
}
610+
}
611+
590612
public void testStringLength() {
591613
try (EsqlQueryResponse results = run("from test | eval l = length(color)")) {
592614
logger.info(results);

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

+1
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

+1
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)