Skip to content

Commit 2046178

Browse files
UT fixes
1 parent ed34ca4 commit 2046178

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupJoinTypesIT.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import static org.elasticsearch.xpack.esql.core.type.DataType.TEXT;
7777
import static org.elasticsearch.xpack.esql.core.type.DataType.TSID_DATA_TYPE;
7878
import static org.elasticsearch.xpack.esql.core.type.DataType.UNDER_CONSTRUCTION;
79+
import static org.hamcrest.Matchers.anyOf;
7980
import static org.hamcrest.Matchers.containsString;
8081
import static org.hamcrest.Matchers.equalTo;
8182
import static org.hamcrest.Matchers.is;
@@ -226,7 +227,7 @@ public LookupJoinTypesIT(BinaryComparisonOperation operation) {
226227

227228
// Tests for all unsupported types
228229
DataType[] unsupported = Join.UNSUPPORTED_TYPES;
229-
boolean isNonEqualityComparison = operation == BinaryComparisonOperation.GT
230+
boolean isLessOrGreater = operation == BinaryComparisonOperation.GT
230231
|| operation == BinaryComparisonOperation.GTE
231232
|| operation == BinaryComparisonOperation.LT
232233
|| operation == BinaryComparisonOperation.LTE;
@@ -256,7 +257,7 @@ public LookupJoinTypesIT(BinaryComparisonOperation operation) {
256257
continue;
257258
}
258259
if (operation != null && type == DENSE_VECTOR
259-
|| isNonEqualityComparison
260+
|| isLessOrGreater
260261
&& (type == GEO_POINT || type == GEO_SHAPE || type == CARTESIAN_POINT || type == CARTESIAN_SHAPE)) {
261262
configs.addUnsupportedComparisonFails(type, type, operation);
262263
} else {
@@ -290,7 +291,7 @@ public LookupJoinTypesIT(BinaryComparisonOperation operation) {
290291
assertThat("Claiming supported for unsupported type: " + type, List.of(unsupported).contains(type), is(false));
291292
if (existingIndex(existing, type, type, operation) == false) {
292293
// Only add the configuration if it doesn't already exist
293-
if (type == BOOLEAN && isNonEqualityComparison) {
294+
if (type == BOOLEAN && isLessOrGreater) {
294295
// Boolean does not support inequality operations
295296
configs.addUnsupportedComparisonFails(type, type, operation);
296297
} else {
@@ -327,8 +328,14 @@ public LookupJoinTypesIT(BinaryComparisonOperation operation) {
327328
for (DataType mainType : supported) {
328329
for (DataType lookupType : supported) {
329330
if (existingIndex(existing, mainType, lookupType, operation) == false) {
330-
// Only add the configuration if it doesn't already exist
331-
configs.addFails(mainType, lookupType);
331+
if (operation == null) {
332+
// Only add the configuration if it doesn't already exist
333+
configs.addFails(mainType, lookupType);
334+
} else if (isLessOrGreater) {
335+
configs.addIncompatibleDifferentTypesLessGreater(mainType, lookupType, operation);
336+
} else {
337+
configs.addMismatchedComparisonFailsEqualNotEqual(mainType, lookupType, operation);
338+
}
332339
}
333340
}
334341
}
@@ -662,6 +669,46 @@ private void addFails(DataType mainType, DataType lookupType) {
662669
);
663670
}
664671

672+
private void addMismatchedComparisonFailsEqualNotEqual(
673+
DataType mainType,
674+
DataType lookupType,
675+
BinaryComparisonOperation operation
676+
) {
677+
String fieldNameLeft = LOOKUP_INDEX_PREFIX + lookupType.esType() + suffixLeftFieldName(operation);
678+
String fieldNameRight = LOOKUP_INDEX_PREFIX + lookupType.esType();
679+
final Consumer<VerificationException> assertion = e -> {
680+
String errorMessage1 = String.format(
681+
Locale.ROOT,
682+
"first argument of [%s %s %s] is [",
683+
fieldNameLeft,
684+
operation.symbol(),
685+
fieldNameRight
686+
);
687+
String errorMessage3 = String.format(Locale.ROOT, " but was [%s]", lookupType.widenSmallNumeric().typeName());
688+
assertThat(e.getMessage(), containsString(errorMessage1));
689+
assertThat(e.getMessage(), containsString("] so second argument must also be ["));
690+
assertThat(e.getMessage(), containsString(errorMessage3));
691+
};
692+
693+
add(new TestConfigFails<>(mainType, lookupType, VerificationException.class, assertion, operation));
694+
}
695+
696+
private void addIncompatibleDifferentTypesLessGreater(DataType mainType, DataType lookupType, BinaryComparisonOperation operation) {
697+
String fieldNameLeft = LOOKUP_INDEX_PREFIX + lookupType.esType() + suffixLeftFieldName(operation);
698+
String fieldNameRight = LOOKUP_INDEX_PREFIX + lookupType.esType();
699+
700+
String errorMessage1 = String.format(Locale.ROOT, "argument of [%s %s %s]", fieldNameLeft, operation.symbol(), fieldNameRight);
701+
702+
add(new TestConfigFails<>(mainType, lookupType, VerificationException.class, e -> {
703+
assertThat(e.getMessage().toLowerCase(Locale.ROOT), containsString(errorMessage1));
704+
assertThat(
705+
e.getMessage().toLowerCase(Locale.ROOT),
706+
anyOf(List.of(containsString(mainType.widenSmallNumeric().typeName()), containsString("numeric")))
707+
);
708+
assertThat(e.getMessage().toLowerCase(Locale.ROOT), containsString(lookupType.typeName()));
709+
}, operation));
710+
}
711+
665712
private void addUnsupportedComparisonFails(DataType mainType, DataType lookupType, BinaryComparisonOperation operation) {
666713
String fieldNameLeft = LOOKUP_INDEX_PREFIX + lookupType.esType() + suffixLeftFieldName(operation);
667714
String fieldNameRight = LOOKUP_INDEX_PREFIX + lookupType.esType();

0 commit comments

Comments
 (0)