Skip to content

Commit 33dd062

Browse files
committed
Fix error tests
1 parent 9259f49 commit 33dd062

File tree

1 file changed

+18
-2
lines changed
  • x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
package org.elasticsearch.xpack.esql.expression.function.fulltext;
99

10+
import org.elasticsearch.index.query.QueryBuilder;
1011
import org.elasticsearch.xpack.esql.core.expression.Expression;
12+
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
1113
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
1214
import org.elasticsearch.xpack.esql.core.tree.Source;
1315
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -21,6 +23,8 @@
2123
import java.util.Locale;
2224
import java.util.Set;
2325

26+
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
27+
import static org.elasticsearch.xpack.esql.planner.TranslatorHandler.TRANSLATOR_HANDLER;
2428
import static org.hamcrest.Matchers.equalTo;
2529

2630
public class MatchErrorTests extends ErrorsForCasesWithoutExamplesTestCase {
@@ -31,7 +35,14 @@ protected List<TestCaseSupplier> cases() {
3135

3236
@Override
3337
protected Expression build(Source source, List<Expression> args) {
34-
return new Match(source, args.get(0), args.get(1), null);
38+
Match match = new Match(source, args.get(0), args.get(1), args.size() > 2 ? args.get(2) : null);
39+
// We need to add the QueryBuilder to the match expression, as it is used to implement equals() and hashCode() and
40+
// thus test the serialization methods. But we can only do this if the parameters make sense .
41+
if (args.get(0) instanceof FieldAttribute && args.get(1).foldable()) {
42+
QueryBuilder queryBuilder = TRANSLATOR_HANDLER.asQuery(match).asBuilder();
43+
match.replaceQueryBuilder(queryBuilder);
44+
}
45+
return match;
3546
}
3647

3748
@Override
@@ -46,7 +57,8 @@ private static String errorMessageStringForMatch(
4657
List<DataType> signature,
4758
AbstractFunctionTestCase.PositionalErrorMessageSupplier positionalErrorMessageSupplier
4859
) {
49-
for (int i = 0; i < signature.size(); i++) {
60+
boolean invalid = false;
61+
for (int i = 0; i < signature.size() && invalid == false; i++) {
5062
// Need to check for nulls and bad parameters in order
5163
if (signature.get(i) == DataType.NULL) {
5264
return TypeResolutions.ParamOrdinal.fromIndex(i).name().toLowerCase(Locale.ROOT)
@@ -55,6 +67,10 @@ private static String errorMessageStringForMatch(
5567
+ "] cannot be null, received []";
5668
}
5769
if (validPerPosition.get(i).contains(signature.get(i)) == false) {
70+
// Map expressions have different error messages
71+
if (i == 2) {
72+
return format(null, "third argument of [{}] must be a map expression, received []", sourceForSignature(signature));
73+
}
5874
break;
5975
}
6076
}

0 commit comments

Comments
 (0)