|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.esql.plan.logical; |
9 | 9 |
|
| 10 | +import java.util.Collections; |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +import org.elasticsearch.index.IndexMode; |
10 | 14 | import org.elasticsearch.test.ESTestCase; |
| 15 | +import org.elasticsearch.xpack.esql.common.Failures; |
11 | 16 | import org.elasticsearch.xpack.esql.core.expression.Alias; |
12 | 17 | import org.elasticsearch.xpack.esql.core.expression.Attribute; |
13 | 18 | import org.elasticsearch.xpack.esql.core.expression.AttributeSet; |
14 | 19 | import org.elasticsearch.xpack.esql.core.expression.Expression; |
| 20 | +import org.elasticsearch.xpack.esql.core.expression.FieldAttribute; |
15 | 21 | import org.elasticsearch.xpack.esql.core.expression.Literal; |
16 | 22 | import org.elasticsearch.xpack.esql.core.tree.Source; |
17 | 23 | import org.elasticsearch.xpack.esql.core.type.DataType; |
| 24 | +import org.elasticsearch.xpack.esql.core.type.EsField; |
18 | 25 | import org.elasticsearch.xpack.esql.plan.logical.join.Join; |
19 | 26 | import org.elasticsearch.xpack.esql.plan.logical.join.JoinConfig; |
20 | 27 | import org.elasticsearch.xpack.esql.plan.logical.join.JoinTypes; |
|
23 | 30 | import java.util.List; |
24 | 31 | import java.util.Set; |
25 | 32 |
|
| 33 | +import org.elasticsearch.xpack.esql.plan.logical.join.LookupJoin; |
| 34 | + |
26 | 35 | public class JoinTests extends ESTestCase { |
27 | 36 | @AwaitsFix(bugUrl = "Test needs updating to the new JOIN planning") |
28 | 37 | public void testExpressionsAndReferences() { |
@@ -99,4 +108,53 @@ public void testTransformExprs() { |
99 | 108 | private static Alias aliasForLiteral(String name) { |
100 | 109 | return new Alias(Source.EMPTY, name, new Literal(Source.EMPTY, 1, DataType.INTEGER)); |
101 | 110 | } |
| 111 | + |
| 112 | + public void testLookupJoinErrorMessage() { |
| 113 | + Failures failures = new Failures(); |
| 114 | + |
| 115 | + String indexPattern = "test1"; |
| 116 | + Map<String, IndexMode> indexNameWithModes = Collections.emptyMap(); |
| 117 | + |
| 118 | + EsRelation fakeRelation = new EsRelation(Source.EMPTY, indexPattern, IndexMode.LOOKUP, indexNameWithModes, List.of()); |
| 119 | + |
| 120 | + EsField empNoEsField = new EsField("emp_no", DataType.INTEGER, Collections.emptyMap(), false); |
| 121 | + FieldAttribute empNoField = new FieldAttribute(Source.EMPTY, "emp_no", empNoEsField); |
| 122 | + Alias empNoAlias = new Alias(Source.EMPTY, "emp_no", empNoField); |
| 123 | + LogicalPlan left = new Row(Source.EMPTY, List.of(empNoAlias)); |
| 124 | + |
| 125 | + LookupJoin lookupJoin = new LookupJoin(Source.EMPTY, left, fakeRelation, |
| 126 | + new JoinConfig(JoinTypes.LEFT, List.of(), List.of(), List.of())); |
| 127 | + |
| 128 | + lookupJoin.postAnalysisVerification(failures); |
| 129 | + |
| 130 | + String expectedMessage = "Index [test1] exists, but no valid fields for LOOKUP JOIN were found"; |
| 131 | + assertTrue(failures.toString().contains(expectedMessage)); |
| 132 | + } |
| 133 | + |
| 134 | + public void testLookupJoinErrorMessage_MultipleIndices() { |
| 135 | + Failures failures = new Failures(); |
| 136 | + |
| 137 | + String indexPattern = "test1"; |
| 138 | + Map<String, IndexMode> indexNameWithModes = Map.of( |
| 139 | + "test1", IndexMode.LOOKUP, |
| 140 | + "test2", IndexMode.LOOKUP |
| 141 | + ); |
| 142 | + |
| 143 | + EsField languagesEsField = new EsField("languages", DataType.KEYWORD, Collections.emptyMap(), true); |
| 144 | + FieldAttribute languagesField = new FieldAttribute(Source.EMPTY, "languages", languagesEsField); |
| 145 | + EsRelation fakeRelation = new EsRelation(Source.EMPTY, indexPattern, IndexMode.LOOKUP, indexNameWithModes, List.of(languagesField)); |
| 146 | + |
| 147 | + EsField empNoEsField = new EsField("emp_no", DataType.INTEGER, Collections.emptyMap(), false); |
| 148 | + FieldAttribute empNoField = new FieldAttribute(Source.EMPTY, "emp_no", empNoEsField); |
| 149 | + Alias empNoAlias = new Alias(Source.EMPTY, "emp_no", empNoField); |
| 150 | + LogicalPlan left = new Row(Source.EMPTY, List.of(empNoAlias)); |
| 151 | + |
| 152 | + LookupJoin lookupJoin = new LookupJoin(Source.EMPTY, left, fakeRelation, |
| 153 | + new JoinConfig(JoinTypes.LEFT, List.of(), List.of(), List.of())); |
| 154 | + |
| 155 | + lookupJoin.postAnalysisVerification(failures); |
| 156 | + |
| 157 | + String expectedMessage = "Invalid [test1] resolution in lookup mode to [2] indices"; |
| 158 | + assertTrue(failures.toString().contains(expectedMessage)); |
| 159 | + } |
102 | 160 | } |
0 commit comments