Skip to content

Commit 0f90ddb

Browse files
committed
Fix license checks in function unit tests
1 parent f139ac0 commit 0f90ddb

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

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

Lines changed: 3 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/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ public static void testFunctionLicenseChecks() throws Exception {
843843
assertNotNull("License should not be null", license);
844844

845845
// Construct an instance of the class and then call it's licenseCheck method, and compare the results
846-
Object[] args = new Object[signature.size() + 1];
846+
Object[] args = new Object[ctor.getParameterCount()];
847847
args[0] = Source.EMPTY;
848848
for (int i = 0; i < signature.size(); i++) {
849849
args[i + 1] = new Literal(Source.EMPTY, null, signature.get(i));

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.compute.operator.EvalOperator;
1414
import org.elasticsearch.geometry.Point;
1515
import org.elasticsearch.geometry.Rectangle;
16+
import org.elasticsearch.license.License;
1617
import org.elasticsearch.xpack.esql.core.expression.Literal;
1718
import org.elasticsearch.xpack.esql.core.tree.Source;
1819
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -40,6 +41,26 @@ protected interface TriFunction<T, U, V, R> {
4041
R apply(T t, U u, V v);
4142
}
4243

44+
/**
45+
* All spatial grid functions have one license requirement in common, and that is that they are licensed aty PLATINUM level
46+
* oif the spatial field is a shape, otherwise they are licensed at BASIC level. This is to mimic the license requirements
47+
* of the spatial aggregations.
48+
* @param fieldTypes (null for the function itself, otherwise a map of field named to types)
49+
* @return The license requirement for the function with that type signature
50+
*/
51+
protected static License.OperationMode licenseRequirement(List<DataType> fieldTypes) {
52+
if (fieldTypes == null || fieldTypes.isEmpty()) {
53+
// The function itself is not licensed, but the field types are.
54+
return License.OperationMode.BASIC;
55+
}
56+
if (DataType.isSpatialShape(fieldTypes.getFirst())) {
57+
// Only aggregations over shapes are licensed under platinum.
58+
return License.OperationMode.PLATINUM;
59+
}
60+
// All other field types are licensed under basic.
61+
return License.OperationMode.BASIC;
62+
}
63+
4364
private static String getFunctionClassName() {
4465
Class<?> testClass = getTestClass();
4566
String testClassName = testClass.getSimpleName();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.lucene.util.BytesRef;
1414
import org.elasticsearch.common.geo.GeoBoundingBox;
1515
import org.elasticsearch.geometry.utils.Geohash;
16+
import org.elasticsearch.license.License;
1617
import org.elasticsearch.xpack.esql.core.expression.Expression;
1718
import org.elasticsearch.xpack.esql.core.tree.Source;
1819
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -30,6 +31,14 @@ public StGeohashTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> test
3031
this.testCase = testCaseSupplier.get();
3132
}
3233

34+
/**
35+
* Since geo grid functions are primarily used for spatial aggregations,
36+
* we use the same license requirement as the spatial aggregations.
37+
*/
38+
public static License.OperationMode licenseRequirement(List<DataType> fieldTypes) {
39+
return SpatialGridFunctionTestCase.licenseRequirement(fieldTypes);
40+
}
41+
3342
@ParametersFactory
3443
public static Iterable<Object[]> parameters() {
3544
final List<TestCaseSupplier> suppliers = new ArrayList<>();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.lucene.util.BytesRef;
1414
import org.elasticsearch.common.geo.GeoBoundingBox;
1515
import org.elasticsearch.h3.H3;
16+
import org.elasticsearch.license.License;
1617
import org.elasticsearch.xpack.esql.core.expression.Expression;
1718
import org.elasticsearch.xpack.esql.core.tree.Source;
1819
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -30,6 +31,14 @@ public StGeohexTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testC
3031
this.testCase = testCaseSupplier.get();
3132
}
3233

34+
/**
35+
* Other geo grid functions use the same type-specific license requirement as the spatial aggregations, but geohex is licensed
36+
* more strictly, at platinum for all field types.
37+
*/
38+
public static License.OperationMode licenseRequirement(List<DataType> fieldTypes) {
39+
return License.OperationMode.PLATINUM;
40+
}
41+
3342
@ParametersFactory
3443
public static Iterable<Object[]> parameters() {
3544
final List<TestCaseSupplier> suppliers = new ArrayList<>();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import org.apache.lucene.util.BytesRef;
1414
import org.elasticsearch.common.geo.GeoBoundingBox;
15+
import org.elasticsearch.license.License;
1516
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils;
1617
import org.elasticsearch.xpack.esql.core.expression.Expression;
1718
import org.elasticsearch.xpack.esql.core.tree.Source;
@@ -30,6 +31,14 @@ public StGeotileTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> test
3031
this.testCase = testCaseSupplier.get();
3132
}
3233

34+
/**
35+
* Since geo grid functions are primarily used for spatial aggregations,
36+
* we use the same license requirement as the spatial aggregations.
37+
*/
38+
public static License.OperationMode licenseRequirement(List<DataType> fieldTypes) {
39+
return SpatialGridFunctionTestCase.licenseRequirement(fieldTypes);
40+
}
41+
3342
@ParametersFactory
3443
public static Iterable<Object[]> parameters() {
3544
final List<TestCaseSupplier> suppliers = new ArrayList<>();

0 commit comments

Comments
 (0)