Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package org.elasticsearch.xpack.esql.analysis;

import org.elasticsearch.Build;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -93,6 +94,10 @@ public void testInlineCast() throws IOException {
report.humanReadable(true).prettyPrint();
report.startObject();
List<String> namesAndAliases = new ArrayList<>(DataType.namesAndAliases());
if (Build.current().isSnapshot() == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd replace this by a check for the specific capability. Otherwise, it's easy to forget to change this piece of code once that geotiles get enabled permanently.

Also applies to the other test fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Some types do not have a converter in release builds
namesAndAliases.removeAll(List.of("geohash", "geotile", "geohex"));
}
Collections.sort(namesAndAliases);
for (String nameOrAlias : namesAndAliases) {
DataType expectedType = DataType.fromNameOrAlias(nameOrAlias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.matchesRegex;
import static org.hamcrest.Matchers.startsWith;

//@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug")
public class VerifierTests extends ESTestCase {
Expand Down Expand Up @@ -1058,9 +1059,6 @@ public void testSpatialSort() {
"1:136: cannot sort on cartesian_shape",
error(prefix + "| EVAL shape = TO_CARTESIANSHAPE(wkt) | limit 5 | sort shape")
);
assertEquals("1:143: cannot sort on geohash", error(prefix + "| EVAL grid = ST_GEOHASH(TO_GEOPOINT(wkt),1) | limit 5 | sort grid"));
assertEquals("1:143: cannot sort on geotile", error(prefix + "| EVAL grid = ST_GEOTILE(TO_GEOPOINT(wkt),1) | limit 5 | sort grid"));
assertEquals("1:142: cannot sort on geohex", error(prefix + "| EVAL grid = ST_GEOHEX(TO_GEOPOINT(wkt),1) | limit 5 | sort grid"));
var airports = AnalyzerTestUtils.analyzer(loadMapping("mapping-airports.json", "airports"));
var airportsWeb = AnalyzerTestUtils.analyzer(loadMapping("mapping-airports_web.json", "airports_web"));
var countriesBbox = AnalyzerTestUtils.analyzer(loadMapping("mapping-countries_bbox.json", "countries_bbox"));
Expand All @@ -1069,15 +1067,21 @@ public void testSpatialSort() {
assertEquals("1:36: cannot sort on cartesian_point", error("FROM airports_web | LIMIT 5 | sort location", airportsWeb));
assertEquals("1:38: cannot sort on geo_shape", error("FROM countries_bbox | LIMIT 5 | sort shape", countriesBbox));
assertEquals("1:42: cannot sort on cartesian_shape", error("FROM countries_bbox_web | LIMIT 5 | sort shape", countriesBboxWeb));
assertEquals(
"1:67: cannot sort on geohash",
error("FROM airports | LIMIT 5 | EVAL g = ST_GEOHASH(location, 1) | sort g", airports)
);
assertEquals(
"1:67: cannot sort on geotile",
error("FROM airports | LIMIT 5 | EVAL g = ST_GEOTILE(location, 1) | sort g", airports)
);
assertEquals("1:66: cannot sort on geohex", error("FROM airports | LIMIT 5 | EVAL g = ST_GEOHEX(location, 1) | sort g", airports));
for (String grid : new String[] { "geohash", "geotile", "geohex" }) {
String gridFunc = "ST_" + grid.toUpperCase(Locale.ROOT);
String error = Build.current().isSnapshot()
? "1:" + (136 + grid.length()) + ": cannot sort on " + grid
: "1:95: Unknown function [" + gridFunc + "]";
assertThat(grid, error(prefix + "| EVAL grid = " + gridFunc + "(TO_GEOPOINT(wkt),1) | limit 5 | sort grid"), startsWith(error));
error = Build.current().isSnapshot()
? "1:" + (63 + grid.length()) + ": cannot sort on " + grid
: "1:39: Unknown function [" + gridFunc + "]";
assertThat(
grid,
error("FROM airports | LIMIT 5 | EVAL grid = " + gridFunc + "(location, 1) | sort grid", airports),
startsWith(error)
);
}
}

public void testSourceSorting() {
Expand Down Expand Up @@ -2073,7 +2077,9 @@ public void testChangePoint() {
public void testChangePoint_keySortable() {
assumeTrue("change_point must be enabled", EsqlCapabilities.Cap.CHANGE_POINT.isEnabled());
List<DataType> sortableTypes = List.of(BOOLEAN, DOUBLE, DATE_NANOS, DATETIME, INTEGER, IP, KEYWORD, LONG, UNSIGNED_LONG, VERSION);
List<DataType> unsortableTypes = List.of(CARTESIAN_POINT, CARTESIAN_SHAPE, GEO_POINT, GEO_SHAPE, GEOHASH, GEOTILE, GEOHEX);
List<DataType> unsortableTypes = Build.current().isSnapshot()
? List.of(CARTESIAN_POINT, CARTESIAN_SHAPE, GEO_POINT, GEO_SHAPE, GEOHASH, GEOTILE, GEOHEX)
: List.of(CARTESIAN_POINT, CARTESIAN_SHAPE, GEO_POINT, GEO_SHAPE);
for (DataType type : sortableTypes) {
query(Strings.format("ROW key=NULL::%s, value=0\n | CHANGE_POINT value ON key", type));
}
Expand All @@ -2088,21 +2094,23 @@ public void testChangePoint_keySortable() {
public void testChangePoint_valueNumeric() {
assumeTrue("change_point must be enabled", EsqlCapabilities.Cap.CHANGE_POINT.isEnabled());
List<DataType> numericTypes = List.of(DOUBLE, INTEGER, LONG, UNSIGNED_LONG);
List<DataType> nonNumericTypes = List.of(
BOOLEAN,
CARTESIAN_POINT,
CARTESIAN_SHAPE,
DATE_NANOS,
DATETIME,
GEO_POINT,
GEO_SHAPE,
GEOHASH,
GEOTILE,
GEOHEX,
IP,
KEYWORD,
VERSION
);
List<DataType> nonNumericTypes = Build.current().isSnapshot()
? List.of(
BOOLEAN,
CARTESIAN_POINT,
CARTESIAN_SHAPE,
DATE_NANOS,
DATETIME,
GEO_POINT,
GEO_SHAPE,
GEOHASH,
GEOTILE,
GEOHEX,
IP,
KEYWORD,
VERSION
)
: List.of(BOOLEAN, CARTESIAN_POINT, CARTESIAN_SHAPE, DATE_NANOS, DATETIME, GEO_POINT, GEO_SHAPE, IP, KEYWORD, VERSION);
for (DataType type : numericTypes) {
query(Strings.format("ROW key=0, value=NULL::%s\n | CHANGE_POINT value ON key", type));
}
Expand Down