浏览代码

ESQL: Move `originalTypes` method to `FieldAttribute` (#126838)

This moves `originalTypes()` from `Attribute` to `FieldAttribute`, since
only a `FieldAttribute` (and its subclasses) can refer to a field with
multiple types.

Addresses:
https://github.com/elastic/elasticsearch/pull/124913/files#r1996239008
Bogdan Pintea 5 月之前
父节点
当前提交
bad35edcc4

+ 0 - 10
x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Attribute.java

@@ -134,14 +134,4 @@ public abstract class Attribute extends NamedExpression {
     }
 
     protected abstract String label();
-
-    /**
-     * If this field is unsupported this contains the underlying ES types. If there
-     * is a type conflict this will have many elements, some or all of which may
-     * be actually supported types.
-     */
-    @Nullable
-    public List<String> originalTypes() {
-        return null;
-    }
 }

+ 4 - 1
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/UnsupportedAttribute.java

@@ -174,7 +174,10 @@ public final class UnsupportedAttribute extends FieldAttribute implements Unreso
         return super.innerEquals(other) && hasCustomMessage == other.hasCustomMessage && Objects.equals(message, other.message);
     }
 
-    @Override
+    /**
+     * This contains all the underlying ES types.
+     * On a type conflict this will have many elements, some or all of which may be actually supported types.
+     */
     public List<String> originalTypes() {
         return field().getOriginalTypes();
     }

+ 5 - 4
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/TransportEsqlQueryAction.java

@@ -50,6 +50,7 @@ import org.elasticsearch.xpack.esql.enrich.EnrichLookupService;
 import org.elasticsearch.xpack.esql.enrich.EnrichPolicyResolver;
 import org.elasticsearch.xpack.esql.enrich.LookupFromIndexService;
 import org.elasticsearch.xpack.esql.execution.PlanExecutor;
+import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute;
 import org.elasticsearch.xpack.esql.inference.InferenceRunner;
 import org.elasticsearch.xpack.esql.session.Configuration;
 import org.elasticsearch.xpack.esql.session.EsqlSession.PlanRunner;
@@ -324,12 +325,12 @@ public class TransportEsqlQueryAction extends HandledTransportAction<EsqlQueryRe
     private EsqlQueryResponse toResponse(Task task, EsqlQueryRequest request, Configuration configuration, Result result) {
         List<ColumnInfoImpl> columns = result.schema().stream().map(c -> {
             List<String> originalTypes;
-            if (c.originalTypes() == null) {
-                originalTypes = null;
-            } else {
+            if (c instanceof UnsupportedAttribute ua) {
                 // Sort the original types so they are easier to test against and prettier.
-                originalTypes = new ArrayList<>(c.originalTypes());
+                originalTypes = new ArrayList<>(ua.originalTypes());
                 Collections.sort(originalTypes);
+            } else {
+                originalTypes = null;
             }
             return new ColumnInfoImpl(c.name(), c.dataType().outputType(), originalTypes);
         }).toList();