|
8 | 8 | package org.elasticsearch.xpack.esql.analysis; |
9 | 9 |
|
10 | 10 | import org.elasticsearch.Build; |
| 11 | +import org.elasticsearch.common.Strings; |
11 | 12 | import org.elasticsearch.common.logging.LoggerMessageFormat; |
12 | 13 | import org.elasticsearch.test.ESTestCase; |
13 | 14 | import org.elasticsearch.xpack.esql.VerificationException; |
|
36 | 37 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.paramAsConstant; |
37 | 38 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.withDefaultLimitWarning; |
38 | 39 | 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; |
39 | 43 | import static org.elasticsearch.xpack.esql.core.type.DataType.COUNTER_DOUBLE; |
40 | 44 | import static org.elasticsearch.xpack.esql.core.type.DataType.COUNTER_INTEGER; |
41 | 45 | 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; |
42 | 54 | import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD; |
| 55 | +import static org.elasticsearch.xpack.esql.core.type.DataType.LONG; |
43 | 56 | import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG; |
| 57 | +import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION; |
44 | 58 | import static org.hamcrest.Matchers.containsString; |
45 | 59 | import static org.hamcrest.Matchers.equalTo; |
46 | 60 | import static org.hamcrest.Matchers.instanceOf; |
@@ -2007,15 +2021,45 @@ public void testChangePoint() { |
2007 | 2021 | var airports = AnalyzerTestUtils.analyzer(loadMapping("mapping-airports.json", "airports")); |
2008 | 2022 | assertEquals("1:30: Unknown column [blahblah]", error("FROM airports | CHANGE_POINT blahblah ON scalerank", airports)); |
2009 | 2023 | 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 | + } |
2019 | 2063 | } |
2020 | 2064 |
|
2021 | 2065 | public void testSortByAggregate() { |
@@ -2051,13 +2095,7 @@ public void testMatchOptions() { |
2051 | 2095 | query("FROM test | WHERE match(first_name, \"Jean\", {\"auto_generate_synonyms_phrase_query\": true})"); |
2052 | 2096 |
|
2053 | 2097 | // 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 }; |
2061 | 2099 | for (Map.Entry<String, DataType> allowedOptions : Match.ALLOWED_OPTIONS.entrySet()) { |
2062 | 2100 | String optionName = allowedOptions.getKey(); |
2063 | 2101 | DataType optionType = allowedOptions.getValue(); |
|
0 commit comments