|
9 | 9 |
|
10 | 10 | import org.elasticsearch.common.settings.Settings;
|
11 | 11 | import org.elasticsearch.test.ESTestCase;
|
| 12 | +import org.elasticsearch.xpack.core.enrich.EnrichPolicy; |
| 13 | +import org.elasticsearch.xpack.esql.enrich.EnrichPolicyResolution; |
| 14 | +import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry; |
12 | 15 | import org.elasticsearch.xpack.esql.expression.function.aggregate.Max;
|
13 | 16 | import org.elasticsearch.xpack.esql.plan.logical.EsqlUnresolvedRelation;
|
14 | 17 | import org.elasticsearch.xpack.esql.plan.logical.Eval;
|
|
29 | 32 | import org.elasticsearch.xpack.ql.plan.logical.EsRelation;
|
30 | 33 | import org.elasticsearch.xpack.ql.plan.logical.Filter;
|
31 | 34 | import org.elasticsearch.xpack.ql.plan.logical.Limit;
|
| 35 | +import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; |
32 | 36 | import org.elasticsearch.xpack.ql.plan.logical.OrderBy;
|
33 | 37 | import org.elasticsearch.xpack.ql.type.DataType;
|
34 | 38 | import org.elasticsearch.xpack.ql.type.DataTypes;
|
35 | 39 | import org.elasticsearch.xpack.ql.type.TypesTests;
|
36 | 40 |
|
37 | 41 | import java.util.List;
|
38 | 42 | import java.util.Map;
|
| 43 | +import java.util.Set; |
39 | 44 | import java.util.stream.IntStream;
|
40 | 45 |
|
| 46 | +import static org.elasticsearch.xpack.esql.EsqlTestUtils.TEST_VERIFIER; |
41 | 47 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.as;
|
| 48 | +import static org.elasticsearch.xpack.esql.EsqlTestUtils.configuration; |
42 | 49 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.withDefaultLimitWarning;
|
43 | 50 | import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.analyze;
|
44 | 51 | import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.analyzer;
|
@@ -1311,6 +1318,27 @@ public void testEnrichExcludesPolicyKey() {
|
1311 | 1318 | assertThat(e.getMessage(), containsString("Unknown column [id]"));
|
1312 | 1319 | }
|
1313 | 1320 |
|
| 1321 | + public void testEnrichFieldsIncludeMatchField() { |
| 1322 | + String query = """ |
| 1323 | + FROM test |
| 1324 | + | EVAL x = to_string(languages) |
| 1325 | + | ENRICH languages ON x |
| 1326 | + | KEEP language_name, language_code |
| 1327 | + """; |
| 1328 | + IndexResolution testIndex = loadMapping("mapping-basic.json", "test"); |
| 1329 | + IndexResolution languageIndex = loadMapping("mapping-languages.json", "languages"); |
| 1330 | + var enrichPolicy = new EnrichPolicy("match", null, List.of("unused"), "language_code", List.of("language_code", "language_name")); |
| 1331 | + EnrichResolution enrichResolution = new EnrichResolution( |
| 1332 | + Set.of(new EnrichPolicyResolution("languages", enrichPolicy, languageIndex)), |
| 1333 | + Set.of("languages") |
| 1334 | + ); |
| 1335 | + AnalyzerContext context = new AnalyzerContext(configuration(query), new EsqlFunctionRegistry(), testIndex, enrichResolution); |
| 1336 | + Analyzer analyzer = new Analyzer(context, TEST_VERIFIER); |
| 1337 | + LogicalPlan plan = analyze(query, analyzer); |
| 1338 | + var limit = as(plan, Limit.class); |
| 1339 | + assertThat(Expressions.names(limit.output()), contains("language_name", "language_code")); |
| 1340 | + } |
| 1341 | + |
1314 | 1342 | public void testChainedEvalFieldsUse() {
|
1315 | 1343 | var query = "from test | eval x0 = pow(salary, 1), x1 = pow(x0, 2), x2 = pow(x1, 3)";
|
1316 | 1344 | int additionalEvals = randomIntBetween(0, 5);
|
|
0 commit comments