|
17 | 17 | import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.Add;
|
18 | 18 | import org.elasticsearch.xpack.esql.parser.EsqlParser;
|
19 | 19 | import org.elasticsearch.xpack.esql.plan.logical.Eval;
|
| 20 | +import org.elasticsearch.xpack.esql.plan.logical.MvExpand; |
| 21 | +import org.elasticsearch.xpack.esql.plan.logical.local.EsqlProject; |
20 | 22 | import org.elasticsearch.xpack.esql.plan.logical.local.LocalRelation;
|
21 | 23 | import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier;
|
22 | 24 | import org.elasticsearch.xpack.esql.stats.SearchStats;
|
@@ -181,6 +183,37 @@ public void testMissingFieldInSort() {
|
181 | 183 | var source = as(limit.child(), EsRelation.class);
|
182 | 184 | }
|
183 | 185 |
|
| 186 | + /** |
| 187 | + * Expects |
| 188 | + * EsqlProject[[first_name{f}#6]] |
| 189 | + * \_Limit[1000[INTEGER]] |
| 190 | + * \_MvExpand[last_name{f}#9,last_name{r}#15] |
| 191 | + * \_Limit[1000[INTEGER]] |
| 192 | + * \_EsRelation[test][_meta_field{f}#11, emp_no{f}#5, first_name{f}#6, ge..] |
| 193 | + */ |
| 194 | + public void testMissingFieldInMvExpand() { |
| 195 | + var plan = plan(""" |
| 196 | + from test |
| 197 | + | mv_expand last_name |
| 198 | + | keep first_name, last_name |
| 199 | + """); |
| 200 | + |
| 201 | + var testStats = statsForMissingField("last_name"); |
| 202 | + var localPlan = localPlan(plan, testStats); |
| 203 | + |
| 204 | + var project = as(localPlan, EsqlProject.class); |
| 205 | + var projections = project.projections(); |
| 206 | + assertThat(Expressions.names(projections), contains("first_name", "last_name")); |
| 207 | + |
| 208 | + var limit = as(project.child(), Limit.class); |
| 209 | + // MvExpand cannot be optimized (yet) because the target NamedExpression cannot be replaced with a NULL literal |
| 210 | + // https://github.com/elastic/elasticsearch/issues/109974 |
| 211 | + // See LocalLogicalPlanOptimizer.ReplaceMissingFieldWithNull |
| 212 | + var mvExpand = as(limit.child(), MvExpand.class); |
| 213 | + var limit2 = as(mvExpand.child(), Limit.class); |
| 214 | + as(limit2.child(), EsRelation.class); |
| 215 | + } |
| 216 | + |
184 | 217 | /**
|
185 | 218 | * Expects
|
186 | 219 | * EsqlProject[[x{r}#3]]
|
|
0 commit comments