Skip to content

Commit 84109f1

Browse files
committed
Basic support for DATE_RANGE field type in ESQL
1 parent 3c20f0a commit 84109f1

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.lucene.search.SortField;
1616
import org.apache.lucene.util.BytesRef;
1717
import org.elasticsearch.ElasticsearchException;
18+
import org.elasticsearch.TransportVersion;
1819
import org.elasticsearch.common.Explicit;
1920
import org.elasticsearch.common.geo.ShapeRelation;
2021
import org.elasticsearch.common.network.InetAddresses;
@@ -63,6 +64,8 @@ public class RangeFieldMapper extends FieldMapper {
6364
public static final boolean DEFAULT_INCLUDE_UPPER = true;
6465
public static final boolean DEFAULT_INCLUDE_LOWER = true;
6566

67+
public static final TransportVersion ESQL_DATE_RANGE_CREATED_VERSION = TransportVersion.fromName("esql_date_range_created_version");
68+
6669
public static class Defaults {
6770
public static final DateFormatter DATE_FORMATTER = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER;
6871
public static final Locale LOCALE = DateFieldMapper.DEFAULT_LOCALE;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9185000
1+
9187000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
esql_plan_with_no_columns,9186000
1+
esql_date_range_created_version,9187000

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.stream.Collectors;
3434

3535
import static java.util.stream.Collectors.toMap;
36+
import static org.elasticsearch.index.mapper.RangeFieldMapper.ESQL_DATE_RANGE_CREATED_VERSION;
3637

3738
/**
3839
* This enum represents data types the ES|QL query processing layer is able to
@@ -270,12 +271,7 @@ public enum DataType implements Writeable {
270271
* Nanosecond precision date, stored as a 64-bit signed number.
271272
*/
272273
DATE_NANOS(builder().esType("date_nanos").estimatedSize(Long.BYTES).docValues().supportedOnAllNodes()),
273-
DATE_RANGE(
274-
builder().esType("date_range")
275-
.estimatedSize(2 * Long.BYTES)
276-
.docValues()
277-
.supportedOn(DataTypesTransportVersions.ESQL_DATE_RANGE_CREATED_VERSION)
278-
),
274+
DATE_RANGE(builder().esType("date_range").estimatedSize(2 * Long.BYTES).docValues().supportedOn(ESQL_DATE_RANGE_CREATED_VERSION)),
279275
/**
280276
* IP addresses. IPv4 address are always
281277
* <a href="https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5">embedded</a>
@@ -989,8 +985,5 @@ private static class DataTypesTransportVersions {
989985
"esql_aggregate_metric_double_created_version"
990986
);
991987

992-
private static final TransportVersion ESQL_DATE_RANGE_CREATED_VERSION = TransportVersion.fromName(
993-
"esql_date_range_created_version"
994-
);
995988
}
996989
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/DateRangeBlockBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package org.elasticsearch.compute.data;
99

1010
import org.elasticsearch.TransportVersion;
11-
import org.elasticsearch.TransportVersions;
1211
import org.elasticsearch.common.io.stream.GenericNamedWriteable;
1312
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1413
import org.elasticsearch.common.io.stream.StreamInput;
@@ -18,6 +17,8 @@
1817

1918
import java.io.IOException;
2019

20+
import static org.elasticsearch.index.mapper.RangeFieldMapper.ESQL_DATE_RANGE_CREATED_VERSION;
21+
2122
public class DateRangeBlockBuilder extends AbstractBlockBuilder implements BlockLoader.DateRangeBuilder {
2223

2324
private LongBlockBuilder fromBuilder;
@@ -161,7 +162,7 @@ public String getWriteableName() {
161162

162163
@Override
163164
public TransportVersion getMinimalSupportedVersion() {
164-
return TransportVersions.NEW_SEMANTIC_QUERY_INTERCEPTORS;
165+
return ESQL_DATE_RANGE_CREATED_VERSION;
165166
}
166167

167168
@Override

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/AllSupportedFieldsTestCase.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,9 @@ private Matcher<?> expectedValue(DataType type) {
448448
yield nullValue();
449449
}
450450
case DATE_RANGE -> {
451-
if (denseVectorAggMetricDoubleIfFns()) {
452-
yield nullValue();
453-
}
454-
Matcher<String> expected = equalTo("{\"gte\":\"1989-01-01T00:00:00.000Z\",\"lt\":\"2025-01-01T00:00:00.000Z\"}");
455-
yield anyOf(nullValue(), expected);
451+
// Currently, we cannot tell if all nodes support it or not so we treat it as unsupported.
452+
// TODO: Fix this once we know the node versions.
453+
yield nullValue();
456454
}
457455
default -> throw new AssertionError("unsupported field type [" + type + "]");
458456
};

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,21 @@ public void resolveAsMergedMapping(
9494
createFieldCapsRequest(indexWildcard, fieldNames, requestFilter, includeAllDimensions),
9595
listener.delegateFailureAndWrap(
9696
(l, response) -> l.onResponse(
97-
mergedMappings(indexWildcard, new FieldsInfo(response, supportsAggregateMetricDouble, supportsDenseVector, supportsDateRange))
97+
mergedMappings(
98+
indexWildcard,
99+
new FieldsInfo(response, supportsAggregateMetricDouble, supportsDenseVector, supportsDateRange)
100+
)
98101
)
99102
)
100103
);
101104
}
102105

103-
public record FieldsInfo(FieldCapabilitiesResponse caps, boolean supportAggregateMetricDouble, boolean supportDenseVector, boolean supportDateRange) {}
106+
public record FieldsInfo(
107+
FieldCapabilitiesResponse caps,
108+
boolean supportAggregateMetricDouble,
109+
boolean supportDenseVector,
110+
boolean supportDateRange
111+
) {}
104112

105113
// public for testing only
106114
public static IndexResolution mergedMappings(String indexPattern, FieldsInfo fieldsInfo) {

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3807,7 +3807,12 @@ private static LogicalPlan analyzeWithEmptyFieldCapsResponse(String query) throw
38073807
List<FieldCapabilitiesIndexResponse> idxResponses = List.of(
38083808
new FieldCapabilitiesIndexResponse("idx", "idx", Map.of(), true, IndexMode.STANDARD)
38093809
);
3810-
IndexResolver.FieldsInfo caps = new IndexResolver.FieldsInfo(new FieldCapabilitiesResponse(idxResponses, List.of()), true, true, true);
3810+
IndexResolver.FieldsInfo caps = new IndexResolver.FieldsInfo(
3811+
new FieldCapabilitiesResponse(idxResponses, List.of()),
3812+
true,
3813+
true,
3814+
true
3815+
);
38113816
IndexResolution resolution = IndexResolver.mergedMappings("test*", caps);
38123817
var analyzer = analyzer(resolution, TEST_VERIFIER, configuration(query));
38133818
return analyze(query, analyzer);

0 commit comments

Comments
 (0)