Skip to content

Commit fdedf0e

Browse files
committed
Added type error tests and reduced precision to only support integer
1 parent 0b85905 commit fdedf0e

File tree

4 files changed

+128
-2
lines changed

4 files changed

+128
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND;
3434
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.THIRD;
3535
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
36-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isWholeNumber;
3736
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_POINT;
3837
import static org.elasticsearch.xpack.esql.core.type.DataType.GEO_SHAPE;
38+
import static org.elasticsearch.xpack.esql.core.type.DataType.INTEGER;
3939
import static org.elasticsearch.xpack.esql.core.util.SpatialCoordinateTypes.GEO;
4040

4141
/**
@@ -97,7 +97,7 @@ protected TypeResolution resolveType() {
9797
return resolution;
9898
}
9999

100-
resolution = isWholeNumber(parameter(), sourceText(), SECOND);
100+
resolution = isType(parameter, t -> t.equals(INTEGER), sourceText(), SECOND, INTEGER.typeName());
101101
if (resolution.unresolved()) {
102102
return resolution;
103103
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.scalar.spatial;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.core.type.DataType;
13+
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
14+
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
15+
import org.hamcrest.Matcher;
16+
17+
import java.util.List;
18+
import java.util.Set;
19+
20+
import static org.hamcrest.Matchers.equalTo;
21+
22+
public class StGeohashErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
23+
@Override
24+
protected List<TestCaseSupplier> cases() {
25+
return paramsToSuppliers(StGeohashTests.parameters());
26+
}
27+
28+
@Override
29+
protected Expression build(Source source, List<Expression> args) {
30+
return new StGeohash(source, args.get(0), args.get(1), args.size() > 2 ? args.get(2) : null);
31+
}
32+
33+
@Override
34+
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
35+
return equalTo(typeErrorMessage(true, validPerPosition, signature, (v, p) -> switch (p) {
36+
case 0 -> "geo_point";
37+
case 1 -> "integer";
38+
case 2 -> "geo_shape";
39+
default -> throw new IllegalStateException("Unexpected value: " + p);
40+
}));
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.scalar.spatial;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.core.type.DataType;
13+
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
14+
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
15+
import org.hamcrest.Matcher;
16+
17+
import java.util.List;
18+
import java.util.Set;
19+
20+
import static org.hamcrest.Matchers.equalTo;
21+
22+
public class StGeohexErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
23+
@Override
24+
protected List<TestCaseSupplier> cases() {
25+
return paramsToSuppliers(StGeohexTests.parameters());
26+
}
27+
28+
@Override
29+
protected Expression build(Source source, List<Expression> args) {
30+
return new StGeohex(source, args.get(0), args.get(1), args.size() > 2 ? args.get(2) : null);
31+
}
32+
33+
@Override
34+
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
35+
return equalTo(typeErrorMessage(true, validPerPosition, signature, (v, p) -> switch (p) {
36+
case 0 -> "geo_point";
37+
case 1 -> "integer";
38+
case 2 -> "geo_shape";
39+
default -> throw new IllegalStateException("Unexpected value: " + p);
40+
}));
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.scalar.spatial;
9+
10+
import org.elasticsearch.xpack.esql.core.expression.Expression;
11+
import org.elasticsearch.xpack.esql.core.tree.Source;
12+
import org.elasticsearch.xpack.esql.core.type.DataType;
13+
import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase;
14+
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
15+
import org.hamcrest.Matcher;
16+
17+
import java.util.List;
18+
import java.util.Set;
19+
20+
import static org.hamcrest.Matchers.equalTo;
21+
22+
public class StGeotileErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
23+
@Override
24+
protected List<TestCaseSupplier> cases() {
25+
return paramsToSuppliers(StGeotileTests.parameters());
26+
}
27+
28+
@Override
29+
protected Expression build(Source source, List<Expression> args) {
30+
return new StGeotile(source, args.get(0), args.get(1), args.size() > 2 ? args.get(2) : null);
31+
}
32+
33+
@Override
34+
protected Matcher<String> expectedTypeErrorMatcher(List<Set<DataType>> validPerPosition, List<DataType> signature) {
35+
return equalTo(typeErrorMessage(true, validPerPosition, signature, (v, p) -> switch (p) {
36+
case 0 -> "geo_point";
37+
case 1 -> "integer";
38+
case 2 -> "geo_shape";
39+
default -> throw new IllegalStateException("Unexpected value: " + p);
40+
}));
41+
}
42+
}

0 commit comments

Comments
 (0)