Skip to content

Commit 6b3d019

Browse files
committed
Add code to generate docs for match operator
1 parent 51a8711 commit 6b3d019

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.elasticsearch.xpack.esql.core.util.NumericUtils;
4545
import org.elasticsearch.xpack.esql.core.util.StringUtils;
4646
import org.elasticsearch.xpack.esql.evaluator.EvalMapper;
47+
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
4748
import org.elasticsearch.xpack.esql.expression.function.scalar.conditional.Greatest;
4849
import org.elasticsearch.xpack.esql.expression.function.scalar.nulls.Coalesce;
4950
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
@@ -130,7 +131,9 @@ public abstract class AbstractFunctionTestCase extends ESTestCase {
130131
entry("mod", Mod.class),
131132
entry("neg", Neg.class),
132133
entry("is_null", IsNull.class),
133-
entry("is_not_null", IsNotNull.class)
134+
entry("is_not_null", IsNotNull.class),
135+
// Match operator is both a function and an operator
136+
entry("match_operator", Match.class)
134137
);
135138

136139
private static EsqlFunctionRegistry functionRegistry = new EsqlFunctionRegistry().snapshotRegistry();
@@ -1250,6 +1253,7 @@ private static String binaryOperator(String name) {
12501253
case "greater_than_or_equal" -> ">=";
12511254
case "less_than" -> "<";
12521255
case "less_than_or_equal" -> "<=";
1256+
case "match_operator" -> ":";
12531257
case "mod" -> "%";
12541258
case "mul" -> "*";
12551259
case "not_equals" -> "!=";
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.fulltext;
9+
10+
import com.carrotsearch.randomizedtesting.annotations.Name;
11+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
12+
13+
import org.elasticsearch.xpack.esql.core.type.DataType;
14+
import org.elasticsearch.xpack.esql.expression.function.FunctionName;
15+
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
16+
17+
import java.util.LinkedList;
18+
import java.util.List;
19+
import java.util.function.Supplier;
20+
21+
/**
22+
* This class is only used to generates docs for the match operator - all testing is done in {@link MatchTests}
23+
*/
24+
@FunctionName("match_operator")
25+
public class MatchOperatorTests extends MatchTests {
26+
27+
public MatchOperatorTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
28+
super(testCaseSupplier);
29+
}
30+
31+
@ParametersFactory
32+
public static Iterable<Object[]> parameters() {
33+
// Have a minimal test so that we can generate the docs
34+
List<TestCaseSupplier> suppliers = new LinkedList<>();
35+
addPositiveTestCase(List.of(DataType.KEYWORD, DataType.KEYWORD), suppliers);
36+
return parameterSuppliersFromTypedData(suppliers);
37+
}
38+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/MatchTests.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,11 @@ public MatchTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCase
3636

3737
@ParametersFactory
3838
public static Iterable<Object[]> parameters() {
39-
Set<DataType> supportedTextParams = Set.of(DataType.KEYWORD, DataType.TEXT);
40-
Set<DataType> supportedNumericParams = Set.of(DataType.DOUBLE, DataType.INTEGER);
41-
Set<DataType> supportedFuzzinessParams = Set.of(DataType.INTEGER, DataType.KEYWORD, DataType.TEXT);
42-
List<Set<DataType>> supportedPerPosition = List.of(
43-
supportedTextParams,
44-
supportedTextParams,
45-
supportedNumericParams,
46-
supportedFuzzinessParams
47-
);
39+
List<Set<DataType>> supportedPerPosition = supportedParams();
4840
List<TestCaseSupplier> suppliers = new LinkedList<>();
4941
for (DataType fieldType : DataType.stringTypes()) {
5042
for (DataType queryType : DataType.stringTypes()) {
51-
addPositiveTestCase(List.of(fieldType, queryType), supportedPerPosition, suppliers);
43+
addPositiveTestCase(List.of(fieldType, queryType), suppliers);
5244
addNonFieldTestCase(List.of(fieldType, queryType), supportedPerPosition, suppliers);
5345
}
5446
}
@@ -61,9 +53,21 @@ public static Iterable<Object[]> parameters() {
6153
);
6254
}
6355

64-
private static void addPositiveTestCase(
56+
protected static List<Set<DataType>> supportedParams() {
57+
Set<DataType> supportedTextParams = Set.of(DataType.KEYWORD, DataType.TEXT);
58+
Set<DataType> supportedNumericParams = Set.of(DataType.DOUBLE, DataType.INTEGER);
59+
Set<DataType> supportedFuzzinessParams = Set.of(DataType.INTEGER, DataType.KEYWORD, DataType.TEXT);
60+
List<Set<DataType>> supportedPerPosition = List.of(
61+
supportedTextParams,
62+
supportedTextParams,
63+
supportedNumericParams,
64+
supportedFuzzinessParams
65+
);
66+
return supportedPerPosition;
67+
}
68+
69+
protected static void addPositiveTestCase(
6570
List<DataType> paramDataTypes,
66-
List<Set<DataType>> supportedPerPosition,
6771
List<TestCaseSupplier> suppliers
6872
) {
6973

0 commit comments

Comments
 (0)