Skip to content

Commit 4c43afa

Browse files
committed
And some more tests
1 parent 62f5a83 commit 4c43afa

File tree

12 files changed

+34
-16
lines changed

12 files changed

+34
-16
lines changed

docs/reference/query-languages/esql/_snippets/functions/types/to_string.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/to_string.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,6 @@ emp_no:integer | birth_date:date | hire_date:date
20302030
;
20312031

20322032
dateRange
2033-
required_capability: date_range_field_type
20342033

20352034
from date_ranges;
20362035

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToCartesianShape;
7979
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToDateNanos;
8080
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToDatePeriod;
81+
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToDateRange;
8182
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToDatetime;
8283
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToDegrees;
8384
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToDenseVector;
@@ -470,6 +471,7 @@ private static FunctionDefinition[][] functions() {
470471
def(ToDatePeriod.class, ToDatePeriod::new, "to_dateperiod"),
471472
def(ToDatetime.class, ToDatetime::new, "to_datetime", "to_dt"),
472473
def(ToDateNanos.class, ToDateNanos::new, "to_date_nanos", "to_datenanos"),
474+
def(ToDateRange.class, ToDateRange::new, "to_date_range", "to_daterange"),
473475
def(ToDegrees.class, ToDegrees::new, "to_degrees"),
474476
def(ToDenseVector.class, ToDenseVector::new, "to_dense_vector"),
475477
def(ToDouble.class, ToDouble::new, "to_double", "to_dbl"),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ private TypeResolution resolveValueType(Expression value, int position) {
209209
dataType = value.dataType().noText();
210210
return TypeResolutions.isType(
211211
value,
212-
t -> t != AGGREGATE_METRIC_DOUBLE,
212+
t -> t != AGGREGATE_METRIC_DOUBLE && t != DataType.DATE_RANGE,
213213
sourceText(),
214214
TypeResolutions.ParamOrdinal.fromIndex(position),
215-
originalWasNull ? NULL.typeName() : "any but aggregate_metric_double"
215+
originalWasNull ? NULL.typeName() : "any but aggregate_metric_double or date_range"
216216
);
217217
}
218218
return TypeResolutions.isType(
219219
value,
220-
t -> t.noText() == dataType && t != AGGREGATE_METRIC_DOUBLE,
220+
t -> t.noText() == dataType && t != AGGREGATE_METRIC_DOUBLE && t != DataType.DATE_RANGE,
221221
sourceText(),
222222
TypeResolutions.ParamOrdinal.fromIndex(position),
223223
dataType.typeName()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public ToString(
113113
"long",
114114
"text",
115115
"unsigned_long",
116-
"version" },
116+
"version",
117+
"date_range" },
117118
description = "Input value. The input can be a single- or multi-valued column or an expression."
118119
) Expression v
119120
) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,9 @@ public void testRegexOnInt() {
16411641

16421642
public void testUnsupportedTypesWithToString() {
16431643
// DATE_PERIOD and TIME_DURATION types have been added, but not really patched through the engine; i.e. supported.
1644-
final String supportedTypes = "aggregate_metric_double or boolean or cartesian_point or cartesian_shape or date_nanos or datetime "
1645-
+ "or dense_vector or geo_point or geo_shape or geohash or geohex or geotile or ip or numeric or string or version";
1644+
final String supportedTypes =
1645+
"aggregate_metric_double or boolean or cartesian_point or cartesian_shape or date_nanos or date_range or datetime "
1646+
+ "or dense_vector or geo_point or geo_shape or geohash or geohex or geotile or ip or numeric or string or version";
16461647
verifyUnsupported(
16471648
"row period = 1 year | eval to_string(period)",
16481649
"line 1:28: argument of [to_string(period)] must be [" + supportedTypes + "], found value [period] type [date_period]"

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/SampleErrorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerP
3838
"first argument of ["
3939
+ sourceForSignature(signature)
4040
+ "] must be [any type except counter types, dense_vector,"
41-
+ " aggregate_metric_double, dense_vector or date_range], found value [] type ["
42-
+ signature.getFirst()
41+
+ " aggregate_metric_double or date_range], found value [] type ["
42+
+ signature.getFirst().esType()
4343
+ "]"
4444
);
4545
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/aggregate/ValuesErrorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerP
4444

4545
@Override
4646
protected void assertNumberOfCheckedSignatures(int checked) {
47-
assertThat(checked, equalTo(2));
47+
assertThat(checked, equalTo(3));
4848
}
4949
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/CaseErrorTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerP
4242
return typeErrorMessage(signature, 0, "boolean");
4343
}
4444
DataType mainType = signature.get(1).noText();
45-
if (mainType == DataType.AGGREGATE_METRIC_DOUBLE) {
46-
return typeErrorMessage(signature, 1, "any but aggregate_metric_double");
45+
if (mainType == DataType.AGGREGATE_METRIC_DOUBLE || mainType == DataType.DATE_RANGE) {
46+
return typeErrorMessage(signature, 1, "any but aggregate_metric_double or date_range");
4747
}
4848
for (int i = 2; i < signature.size(); i++) {
4949
if (i % 2 == 0 && i != signature.size() - 1) {
@@ -56,8 +56,8 @@ protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerP
5656
if (signature.get(i).noText() != mainType) {
5757
return typeErrorMessage(signature, i, mainType.typeName());
5858
}
59-
if (signature.get(i) == DataType.AGGREGATE_METRIC_DOUBLE) {
60-
return typeErrorMessage(signature, i, "any but aggregate_metric_double");
59+
if (signature.get(i) == DataType.AGGREGATE_METRIC_DOUBLE || signature.get(i) == DataType.DATE_RANGE) {
60+
return typeErrorMessage(signature, i, "any but aggregate_metric_double or date_range");
6161
}
6262
}
6363
}

0 commit comments

Comments
 (0)