|
62 | 62 | import org.elasticsearch.xpack.esql.expression.predicate.operator.arithmetic.EsqlArithmeticOperation; |
63 | 63 | import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.In; |
64 | 64 | import org.elasticsearch.xpack.esql.index.EsIndex; |
| 65 | +import org.elasticsearch.xpack.esql.index.IndexResolution; |
65 | 66 | import org.elasticsearch.xpack.esql.parser.ParsingException; |
66 | 67 | import org.elasticsearch.xpack.esql.plan.TableIdentifier; |
67 | 68 | import org.elasticsearch.xpack.esql.plan.logical.Aggregate; |
|
106 | 107 | import java.util.HashSet; |
107 | 108 | import java.util.LinkedHashMap; |
108 | 109 | import java.util.List; |
109 | | -import java.util.Locale; |
110 | 110 | import java.util.Map; |
111 | 111 | import java.util.Set; |
112 | 112 | import java.util.function.Function; |
@@ -199,57 +199,42 @@ private static class ResolveTable extends ParameterizedAnalyzerRule<UnresolvedRe |
199 | 199 |
|
200 | 200 | @Override |
201 | 201 | protected LogicalPlan rule(UnresolvedRelation plan, AnalyzerContext context) { |
202 | | - if (plan.indexMode().equals(IndexMode.LOOKUP)) { |
203 | | - return hackLookupMapping(plan); |
204 | | - } |
205 | | - if (context.indexResolution().isValid() == false) { |
206 | | - return plan.unresolvedMessage().equals(context.indexResolution().toString()) |
| 202 | + return resolveIndex(plan, plan.indexMode().equals(IndexMode.LOOKUP) ? context.lookupResolution() : context.indexResolution()); |
| 203 | + } |
| 204 | + |
| 205 | + private LogicalPlan resolveIndex(UnresolvedRelation plan, IndexResolution indexResolution) { |
| 206 | + if (indexResolution.isValid() == false) { |
| 207 | + return plan.unresolvedMessage().equals(indexResolution.toString()) |
207 | 208 | ? plan |
208 | 209 | : new UnresolvedRelation( |
209 | 210 | plan.source(), |
210 | 211 | plan.table(), |
211 | 212 | plan.frozen(), |
212 | 213 | plan.metadataFields(), |
213 | 214 | plan.indexMode(), |
214 | | - context.indexResolution().toString(), |
| 215 | + indexResolution.toString(), |
215 | 216 | plan.commandName() |
216 | 217 | ); |
217 | 218 | } |
218 | 219 | TableIdentifier table = plan.table(); |
219 | | - if (context.indexResolution().matches(table.index()) == false) { |
| 220 | + if (indexResolution.matches(table.index()) == false) { |
220 | 221 | // TODO: fix this (and tests), or drop check (seems SQL-inherited, where's also defective) |
221 | 222 | new UnresolvedRelation( |
222 | 223 | plan.source(), |
223 | 224 | plan.table(), |
224 | 225 | plan.frozen(), |
225 | 226 | plan.metadataFields(), |
226 | 227 | plan.indexMode(), |
227 | | - "invalid [" + table + "] resolution to [" + context.indexResolution() + "]", |
| 228 | + "invalid [" + table + "] resolution to [" + indexResolution + "]", |
228 | 229 | plan.commandName() |
229 | 230 | ); |
230 | 231 | } |
231 | 232 |
|
232 | | - EsIndex esIndex = context.indexResolution().get(); |
| 233 | + EsIndex esIndex = indexResolution.get(); |
233 | 234 | var attributes = mappingAsAttributes(plan.source(), esIndex.mapping()); |
234 | 235 | attributes.addAll(plan.metadataFields()); |
235 | 236 | return new EsRelation(plan.source(), esIndex, attributes.isEmpty() ? NO_FIELDS : attributes, plan.indexMode()); |
236 | 237 | } |
237 | | - |
238 | | - private LogicalPlan hackLookupMapping(UnresolvedRelation plan) { |
239 | | - if (plan.table().index().toLowerCase(Locale.ROOT).equals("languages_lookup")) { |
240 | | - EsIndex esIndex = new EsIndex( |
241 | | - "languages_lookup", |
242 | | - Map.ofEntries( |
243 | | - Map.entry("language_code", new EsField("language_code", DataType.LONG, Map.of(), true)), |
244 | | - Map.entry("language_name", new EsField("language", DataType.KEYWORD, Map.of(), true)) |
245 | | - ), |
246 | | - Map.of("languages_lookup", IndexMode.LOOKUP) |
247 | | - ); |
248 | | - var attributes = mappingAsAttributes(plan.source(), esIndex.mapping()); |
249 | | - return new EsRelation(plan.source(), esIndex, attributes.isEmpty() ? NO_FIELDS : attributes, plan.indexMode()); |
250 | | - } |
251 | | - return plan; |
252 | | - } |
253 | 238 | } |
254 | 239 |
|
255 | 240 | /** |
|
0 commit comments