Skip to content

Commit bed70ab

Browse files
committed
Check sortable/numeric for all types
1 parent a7c76dd commit bed70ab

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

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

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.esql.analysis;
99

1010
import org.elasticsearch.Build;
11+
import org.elasticsearch.common.Strings;
1112
import org.elasticsearch.common.logging.LoggerMessageFormat;
1213
import org.elasticsearch.test.ESTestCase;
1314
import org.elasticsearch.xpack.esql.VerificationException;
@@ -36,11 +37,24 @@
3637
import static org.elasticsearch.xpack.esql.EsqlTestUtils.paramAsConstant;
3738
import static org.elasticsearch.xpack.esql.EsqlTestUtils.withDefaultLimitWarning;
3839
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.loadMapping;
40+
import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN;
41+
import static org.elasticsearch.xpack.esql.core.type.DataType.CARTESIAN_POINT;
42+
import static org.elasticsearch.xpack.esql.core.type.DataType.CARTESIAN_SHAPE;
3943
import static org.elasticsearch.xpack.esql.core.type.DataType.COUNTER_DOUBLE;
4044
import static org.elasticsearch.xpack.esql.core.type.DataType.COUNTER_INTEGER;
4145
import static org.elasticsearch.xpack.esql.core.type.DataType.COUNTER_LONG;
46+
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
47+
import static org.elasticsearch.xpack.esql.core.type.DataType.DATE_NANOS;
48+
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
49+
import static org.elasticsearch.xpack.esql.core.type.DataType.FLOAT;
50+
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_POINT;
51+
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_SHAPE;
52+
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
53+
import static org.elasticsearch.xpack.esql.core.type.DataType.IP;
4254
import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD;
55+
import static org.elasticsearch.xpack.esql.core.type.DataType.LONG;
4356
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
57+
import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION;
4458
import static org.hamcrest.Matchers.containsString;
4559
import static org.hamcrest.Matchers.equalTo;
4660
import static org.hamcrest.Matchers.instanceOf;
@@ -2007,15 +2021,45 @@ public void testChangePoint() {
20072021
var airports = AnalyzerTestUtils.analyzer(loadMapping("mapping-airports.json", "airports"));
20082022
assertEquals("1:30: Unknown column [blahblah]", error("FROM airports | CHANGE_POINT blahblah ON scalerank", airports));
20092023
assertEquals("1:43: Unknown column [blahblah]", error("FROM airports | CHANGE_POINT scalerank ON blahblah", airports));
2010-
assertEquals(
2011-
"1:17: change point key [location] must be sortable",
2012-
error("FROM airports | CHANGE_POINT scalerank ON location", airports)
2013-
);
2014-
assertEquals("1:17: change point value [name] must be numeric", error("FROM airports | CHANGE_POINT name ON scalerank", airports));
2015-
assertEquals(
2016-
"1:17: change point value [location] must be numeric",
2017-
error("FROM airports | CHANGE_POINT location ON scalerank", airports)
2018-
);
2024+
}
2025+
2026+
public void testChangePoint_keySortable() {
2027+
List<DataType> sortableTypes = List.of(BOOLEAN, DOUBLE, DATE_NANOS, DATETIME, INTEGER, IP, KEYWORD, LONG, UNSIGNED_LONG, VERSION);
2028+
List<DataType> unsortableTypes = List.of(CARTESIAN_POINT, CARTESIAN_SHAPE, GEO_POINT, GEO_SHAPE);
2029+
for (DataType type : sortableTypes) {
2030+
query(Strings.format("ROW key=NULL::%s, value=0\n | CHANGE_POINT value ON key", type));
2031+
}
2032+
for (DataType type : unsortableTypes) {
2033+
assertEquals(
2034+
"2:4: change point key [key] must be sortable",
2035+
error(Strings.format("ROW key=NULL::%s, value=0\n | CHANGE_POINT value ON key", type))
2036+
);
2037+
}
2038+
}
2039+
2040+
public void testChangePoint_valueNumeric() {
2041+
List<DataType> numericTypes = List.of(DOUBLE, INTEGER, LONG, UNSIGNED_LONG);
2042+
List<DataType> nonNumericTypes = List.of(
2043+
BOOLEAN,
2044+
CARTESIAN_POINT,
2045+
CARTESIAN_SHAPE,
2046+
DATE_NANOS,
2047+
DATETIME,
2048+
GEO_POINT,
2049+
GEO_SHAPE,
2050+
IP,
2051+
KEYWORD,
2052+
VERSION
2053+
);
2054+
for (DataType type : numericTypes) {
2055+
query(Strings.format("ROW key=0, value=NULL::%s\n | CHANGE_POINT value ON key", type));
2056+
}
2057+
for (DataType type : nonNumericTypes) {
2058+
assertEquals(
2059+
"2:4: change point value [value] must be numeric",
2060+
error(Strings.format("ROW key=0, value=NULL::%s\n | CHANGE_POINT value ON key", type))
2061+
);
2062+
}
20192063
}
20202064

20212065
public void testSortByAggregate() {
@@ -2051,13 +2095,7 @@ public void testMatchOptions() {
20512095
query("FROM test | WHERE match(first_name, \"Jean\", {\"auto_generate_synonyms_phrase_query\": true})");
20522096

20532097
// Check all data types for available options
2054-
DataType[] optionTypes = new DataType[] {
2055-
DataType.INTEGER,
2056-
DataType.LONG,
2057-
DataType.FLOAT,
2058-
DataType.DOUBLE,
2059-
DataType.KEYWORD,
2060-
DataType.BOOLEAN };
2098+
DataType[] optionTypes = new DataType[] { INTEGER, LONG, FLOAT, DOUBLE, KEYWORD, BOOLEAN };
20612099
for (Map.Entry<String, DataType> allowedOptions : Match.ALLOWED_OPTIONS.entrySet()) {
20622100
String optionName = allowedOptions.getKey();
20632101
DataType optionType = allowedOptions.getValue();

0 commit comments

Comments
 (0)