Skip to content

Commit d1eb012

Browse files
committed
Added identity option to TO_DATE_RANGE, plus more tests
1 parent ed04e57 commit d1eb012

File tree

2 files changed

+36
-5
lines changed
  • x-pack/plugin/esql

2 files changed

+36
-5
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/date.csv-spec

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,3 +2048,27 @@ date_range:date_range | decade:integer | description:keyword
20482048
2010-01-01..2020-01-01 | 2010 | Renaissance Decade
20492049
2020-01-01..2030-01-01 | 2020 | Empowerment Era
20502050
;
2051+
2052+
dateRangeIdentity
2053+
required_capability: date_range_field_type
2054+
2055+
FROM date_ranges
2056+
| WHERE decade == 1900
2057+
| EVAL range = TO_DATE_RANGE(date_range)
2058+
;
2059+
2060+
date_range:date_range | decade:integer | description:keyword | range:date_range
2061+
1900-01-01..1910-01-01 | 1900 | Edwardian Era | 1900-01-01..1910-01-01
2062+
;
2063+
2064+
dateRangeToString
2065+
required_capability: date_range_field_type
2066+
2067+
FROM date_ranges
2068+
| WHERE decade == 1900
2069+
| EVAL range = TO_STRING(date_range)
2070+
;
2071+
2072+
date_range:date_range | decade:integer | description:keyword | range:keyword
2073+
1900-01-01..1910-01-01 | 1900 | Edwardian Era | 1900-01-01T00:00:00.000Z..1909-12-31T23:59:59.999Z
2074+
;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDateRange.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,37 @@
1313
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
1414
import org.elasticsearch.xpack.esql.core.tree.Source;
1515
import org.elasticsearch.xpack.esql.core.type.DataType;
16+
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesTo;
17+
import org.elasticsearch.xpack.esql.expression.function.FunctionAppliesToLifecycle;
1618
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
1719
import org.elasticsearch.xpack.esql.expression.function.Param;
1820

1921
import java.io.IOException;
2022
import java.util.List;
2123
import java.util.Map;
2224

25+
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_RANGE;
26+
2327
public class ToDateRange extends AbstractConvertFunction {
2428
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
2529
Expression.class,
2630
"ToDateRange",
2731
ToDateRange::new
2832
);
2933

30-
private static final Map<DataType, BuildFactory> EVALUATORS = Map.ofEntries(
31-
// TODO
32-
);
34+
private static final Map<DataType, BuildFactory> EVALUATORS = Map.ofEntries(Map.entry(DATE_RANGE, (source, fieldEval) -> fieldEval));
3335

34-
@FunctionInfo(returnType = "DateRange", description = "TBD")
36+
@FunctionInfo(
37+
returnType = "date_range",
38+
preview = true,
39+
appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.PREVIEW) },
40+
description = "Converts an input value to a `date_range` value."
41+
)
3542
public ToDateRange(
3643
Source source,
3744
@Param(
3845
name = "field",
39-
type = {},
46+
type = { "date_range" },
4047
description = "Input value. The input can be a single- or multi-valued column or an expression."
4148
) Expression field
4249
) {

0 commit comments

Comments
 (0)