Skip to content

Commit bad35ed

Browse files
authored
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
1 parent b5e92db commit bad35ed

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

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

-10
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,4 @@ public String nodeString() {
134134
}
135135

136136
protected abstract String label();
137-
138-
/**
139-
* If this field is unsupported this contains the underlying ES types. If there
140-
* is a type conflict this will have many elements, some or all of which may
141-
* be actually supported types.
142-
*/
143-
@Nullable
144-
public List<String> originalTypes() {
145-
return null;
146-
}
147137
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ protected boolean innerEquals(Object o) {
174174
return super.innerEquals(other) && hasCustomMessage == other.hasCustomMessage && Objects.equals(message, other.message);
175175
}
176176

177-
@Override
177+
/**
178+
* This contains all the underlying ES types.
179+
* On a type conflict this will have many elements, some or all of which may be actually supported types.
180+
*/
178181
public List<String> originalTypes() {
179182
return field().getOriginalTypes();
180183
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.elasticsearch.xpack.esql.enrich.EnrichPolicyResolver;
5151
import org.elasticsearch.xpack.esql.enrich.LookupFromIndexService;
5252
import org.elasticsearch.xpack.esql.execution.PlanExecutor;
53+
import org.elasticsearch.xpack.esql.expression.function.UnsupportedAttribute;
5354
import org.elasticsearch.xpack.esql.inference.InferenceRunner;
5455
import org.elasticsearch.xpack.esql.session.Configuration;
5556
import org.elasticsearch.xpack.esql.session.EsqlSession.PlanRunner;
@@ -324,12 +325,12 @@ private EsqlExecutionInfo createEsqlExecutionInfo(EsqlQueryRequest request) {
324325
private EsqlQueryResponse toResponse(Task task, EsqlQueryRequest request, Configuration configuration, Result result) {
325326
List<ColumnInfoImpl> columns = result.schema().stream().map(c -> {
326327
List<String> originalTypes;
327-
if (c.originalTypes() == null) {
328-
originalTypes = null;
329-
} else {
328+
if (c instanceof UnsupportedAttribute ua) {
330329
// Sort the original types so they are easier to test against and prettier.
331-
originalTypes = new ArrayList<>(c.originalTypes());
330+
originalTypes = new ArrayList<>(ua.originalTypes());
332331
Collections.sort(originalTypes);
332+
} else {
333+
originalTypes = null;
333334
}
334335
return new ColumnInfoImpl(c.name(), c.dataType().outputType(), originalTypes);
335336
}).toList();

0 commit comments

Comments
 (0)