|
21 | 21 | import org.elasticsearch.xpack.esql.core.InvalidArgumentException; |
22 | 22 | import org.elasticsearch.xpack.esql.core.expression.EntryExpression; |
23 | 23 | import org.elasticsearch.xpack.esql.core.expression.Expression; |
| 24 | +import org.elasticsearch.xpack.esql.core.expression.FieldAttribute; |
24 | 25 | import org.elasticsearch.xpack.esql.core.expression.FoldContext; |
25 | 26 | import org.elasticsearch.xpack.esql.core.expression.Literal; |
26 | 27 | import org.elasticsearch.xpack.esql.core.expression.MapExpression; |
|
31 | 32 | import org.elasticsearch.xpack.esql.core.tree.Source; |
32 | 33 | import org.elasticsearch.xpack.esql.core.type.DataType; |
33 | 34 | import org.elasticsearch.xpack.esql.core.type.DataTypeConverter; |
| 35 | +import org.elasticsearch.xpack.esql.core.type.MultiTypeEsField; |
34 | 36 | import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper; |
| 37 | +import org.elasticsearch.xpack.esql.expression.function.scalar.convert.AbstractConvertFunction; |
35 | 38 | import org.elasticsearch.xpack.esql.expression.predicate.logical.BinaryLogic; |
36 | 39 | import org.elasticsearch.xpack.esql.expression.predicate.logical.Not; |
37 | 40 | import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates; |
|
57 | 60 | import static org.elasticsearch.xpack.esql.common.Failure.fail; |
58 | 61 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.DEFAULT; |
59 | 62 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isFoldable; |
| 63 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isMapExpression; |
| 64 | +import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull; |
60 | 65 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNullAndFoldable; |
61 | 66 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isString; |
62 | 67 |
|
@@ -365,4 +370,47 @@ protected static void populateOptionsMap( |
365 | 370 | } |
366 | 371 | } |
367 | 372 | } |
| 373 | + |
| 374 | + protected TypeResolution resolveOptions(Expression options, TypeResolutions.ParamOrdinal paramOrdinal) { |
| 375 | + if (options != null) { |
| 376 | + TypeResolution resolution = isNotNull(options, sourceText(), paramOrdinal); |
| 377 | + if (resolution.unresolved()) { |
| 378 | + return resolution; |
| 379 | + } |
| 380 | + // MapExpression does not have a DataType associated with it |
| 381 | + resolution = isMapExpression(options, sourceText(), paramOrdinal); |
| 382 | + if (resolution.unresolved()) { |
| 383 | + return resolution; |
| 384 | + } |
| 385 | + |
| 386 | + try { |
| 387 | + resolvedOptions(); |
| 388 | + } catch (InvalidArgumentException e) { |
| 389 | + return new TypeResolution(e.getMessage()); |
| 390 | + } |
| 391 | + } |
| 392 | + return TypeResolution.TYPE_RESOLVED; |
| 393 | + } |
| 394 | + |
| 395 | + protected Map<String, Object> resolvedOptions() throws InvalidArgumentException { |
| 396 | + return Map.of(); |
| 397 | + } |
| 398 | + |
| 399 | + public static String getNameFromFieldAttribute(FieldAttribute fieldAttribute) { |
| 400 | + String fieldName = fieldAttribute.name(); |
| 401 | + if (fieldAttribute.field() instanceof MultiTypeEsField multiTypeEsField) { |
| 402 | + // If we have multiple field types, we allow the query to be done, but getting the underlying field name |
| 403 | + fieldName = multiTypeEsField.getName(); |
| 404 | + } |
| 405 | + return fieldName; |
| 406 | + } |
| 407 | + |
| 408 | + public static FieldAttribute fieldAsFieldAttribute(Expression field) { |
| 409 | + Expression fieldExpression = field; |
| 410 | + // Field may be converted to other data type (field_name :: data_type), so we need to check the original field |
| 411 | + if (fieldExpression instanceof AbstractConvertFunction convertFunction) { |
| 412 | + fieldExpression = convertFunction.field(); |
| 413 | + } |
| 414 | + return fieldExpression instanceof FieldAttribute fieldAttribute ? fieldAttribute : null; |
| 415 | + } |
368 | 416 | } |
0 commit comments