Skip to content

Commit b3f0c09

Browse files
committed
expand tests
1 parent 71df645 commit b3f0c09

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,34 @@ public void testUnionTypesInferNonNullAggConstraint() {
744744
assertEquals("integer_long_field", unionTypeField.fieldName().string());
745745
}
746746

747+
/**
748+
* \_Aggregate[[first_name{r}#7, $$first_name$temp_name$17{r}#18],[SUM(salary{f}#11,true[BOOLEAN]) AS SUM(salary)#5, first_nam
749+
* e{r}#7, first_name{r}#7 AS last_name#10]]
750+
* \_Eval[[null[KEYWORD] AS first_name#7, null[KEYWORD] AS $$first_name$temp_name$17#18]]
751+
* \_EsRelation[test][_meta_field{f}#12, emp_no{f}#6, first_name{f}#7, ge..]
752+
*/
747753
public void testGroupingByMissingFields() {
748-
var plan = plan("FROM test | STATS AVG(salary) BY first_name, last_name ");
754+
var plan = plan("FROM test | STATS SUM(salary) BY first_name, last_name");
749755
var testStats = statsForMissingField("first_name", "last_name");
750756
var localPlan = localPlan(plan, testStats);
751-
Aggregate aggregate = (Aggregate) localPlan.collectFirstChildren(p -> p instanceof Aggregate).getFirst();
757+
Limit limit = as(localPlan, Limit.class);
758+
Aggregate aggregate = as(limit.child(), Aggregate.class);
752759
assertThat(aggregate.groupings(), hasSize(2));
760+
ReferenceAttribute grouping1 = as(aggregate.groupings().get(0), ReferenceAttribute.class);
761+
ReferenceAttribute grouping2 = as(aggregate.groupings().get(1), ReferenceAttribute.class);
762+
Eval eval = as(aggregate.child(), Eval.class);
763+
assertThat(eval.fields(), hasSize(2));
764+
Alias eval1 = eval.fields().get(0);
765+
Literal literal1 = as(eval1.child(), Literal.class);
766+
assertNull(literal1.value());
767+
assertThat(literal1.dataType(), is(DataType.KEYWORD));
768+
Alias eval2 = eval.fields().get(1);
769+
Literal literal2 = as(eval2.child(), Literal.class);
770+
assertNull(literal2.value());
771+
assertThat(literal2.dataType(), is(DataType.KEYWORD));
772+
assertThat(grouping1.id(), equalTo(eval1.id()));
773+
assertThat(grouping2.id(), equalTo(eval2.id()));
774+
as(eval.child(), EsRelation.class);
753775
}
754776

755777
private IsNotNull isNotNull(Expression field) {

0 commit comments

Comments
 (0)