|
@@ -31,6 +31,7 @@ import org.elasticsearch.test.rest.ESRestTestCase;
|
|
|
import org.elasticsearch.xcontent.ToXContent;
|
|
|
import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.xcontent.XContentType;
|
|
|
+import org.elasticsearch.xpack.esql.AssertWarnings;
|
|
|
import org.elasticsearch.xpack.esql.EsqlTestUtils;
|
|
|
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
|
|
|
import org.junit.After;
|
|
@@ -53,7 +54,6 @@ import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.function.IntFunction;
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
import static java.util.Collections.emptySet;
|
|
|
import static java.util.Map.entry;
|
|
@@ -83,9 +83,6 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger(RestEsqlTestCase.class);
|
|
|
|
|
|
- private static final List<String> NO_WARNINGS = List.of();
|
|
|
- private static final List<Pattern> NO_WARNINGS_REGEX = List.of();
|
|
|
-
|
|
|
private static final String MAPPING_ALL_TYPES;
|
|
|
|
|
|
static {
|
|
@@ -379,7 +376,7 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
options.addHeader("Content-Type", mediaType);
|
|
|
options.addHeader("Accept", "text/csv; header=absent");
|
|
|
request.setOptions(options);
|
|
|
- HttpEntity entity = performRequest(request, NO_WARNINGS, NO_WARNINGS_REGEX);
|
|
|
+ HttpEntity entity = performRequest(request, new AssertWarnings.NoWarnings());
|
|
|
String actual = Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8));
|
|
|
assertEquals("keyword0,0\r\n", actual);
|
|
|
}
|
|
@@ -431,11 +428,13 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
for (String truePredicate : trueForSingleValuesPredicates) {
|
|
|
String comparison = fieldWithType + truePredicate;
|
|
|
var query = requestObjectBuilder().query(format(null, "from {} | where {}", testIndexName(), comparison));
|
|
|
- List<String> expectedWarnings = List.of(
|
|
|
- "Line 1:29: evaluation of [" + comparison + "] failed, treating result as null. Only first 20 failures recorded.",
|
|
|
- "Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value"
|
|
|
+ AssertWarnings assertWarnings = new AssertWarnings.ExactStrings(
|
|
|
+ List.of(
|
|
|
+ "Line 1:29: evaluation of [" + comparison + "] failed, treating result as null. Only first 20 failures recorded.",
|
|
|
+ "Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value"
|
|
|
+ )
|
|
|
);
|
|
|
- var result = runEsql(query, expectedWarnings, NO_WARNINGS_REGEX, mode);
|
|
|
+ var result = runEsql(query, assertWarnings, mode);
|
|
|
|
|
|
var values = as(result.get("values"), ArrayList.class);
|
|
|
assertThat(
|
|
@@ -505,7 +504,7 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
|
|
|
for (String p : predicates) {
|
|
|
var query = requestObjectBuilder().query(format(null, "from {} | where {}", testIndexName(), p));
|
|
|
- var result = runEsql(query, List.of(), NO_WARNINGS_REGEX, mode);
|
|
|
+ var result = runEsql(query, new AssertWarnings.NoWarnings(), mode);
|
|
|
var values = as(result.get("values"), ArrayList.class);
|
|
|
assertThat(
|
|
|
format(null, "Comparison [{}] should return all rows with single values.", p),
|
|
@@ -997,35 +996,26 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> runEsql(RequestObjectBuilder requestObject) throws IOException {
|
|
|
- return runEsql(requestObject, NO_WARNINGS, NO_WARNINGS_REGEX, mode);
|
|
|
+ return runEsql(requestObject, new AssertWarnings.NoWarnings(), mode);
|
|
|
}
|
|
|
|
|
|
public static Map<String, Object> runEsqlSync(RequestObjectBuilder requestObject) throws IOException {
|
|
|
- return runEsqlSync(requestObject, NO_WARNINGS, NO_WARNINGS_REGEX);
|
|
|
+ return runEsqlSync(requestObject, new AssertWarnings.NoWarnings());
|
|
|
}
|
|
|
|
|
|
public static Map<String, Object> runEsqlAsync(RequestObjectBuilder requestObject) throws IOException {
|
|
|
- return runEsqlAsync(requestObject, NO_WARNINGS, NO_WARNINGS_REGEX);
|
|
|
+ return runEsqlAsync(requestObject, new AssertWarnings.NoWarnings());
|
|
|
}
|
|
|
|
|
|
- static Map<String, Object> runEsql(
|
|
|
- RequestObjectBuilder requestObject,
|
|
|
- List<String> expectedWarnings,
|
|
|
- List<Pattern> expectedWarningsRegex,
|
|
|
- Mode mode
|
|
|
- ) throws IOException {
|
|
|
+ static Map<String, Object> runEsql(RequestObjectBuilder requestObject, AssertWarnings assertWarnings, Mode mode) throws IOException {
|
|
|
if (mode == ASYNC) {
|
|
|
- return runEsqlAsync(requestObject, expectedWarnings, expectedWarningsRegex);
|
|
|
+ return runEsqlAsync(requestObject, assertWarnings);
|
|
|
} else {
|
|
|
- return runEsqlSync(requestObject, expectedWarnings, expectedWarningsRegex);
|
|
|
+ return runEsqlSync(requestObject, assertWarnings);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static Map<String, Object> runEsqlSync(
|
|
|
- RequestObjectBuilder requestObject,
|
|
|
- List<String> expectedWarnings,
|
|
|
- List<Pattern> expectedWarningsRegex
|
|
|
- ) throws IOException {
|
|
|
+ public static Map<String, Object> runEsqlSync(RequestObjectBuilder requestObject, AssertWarnings assertWarnings) throws IOException {
|
|
|
requestObject.build();
|
|
|
Request request = prepareRequest(SYNC);
|
|
|
String mediaType = attachBody(requestObject, request);
|
|
@@ -1041,15 +1031,11 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
}
|
|
|
request.setOptions(options);
|
|
|
|
|
|
- HttpEntity entity = performRequest(request, expectedWarnings, expectedWarningsRegex);
|
|
|
+ HttpEntity entity = performRequest(request, assertWarnings);
|
|
|
return entityToMap(entity, requestObject.contentType());
|
|
|
}
|
|
|
|
|
|
- public static Map<String, Object> runEsqlAsync(
|
|
|
- RequestObjectBuilder requestObject,
|
|
|
- List<String> expectedWarnings,
|
|
|
- List<Pattern> expectedWarningsRegex
|
|
|
- ) throws IOException {
|
|
|
+ public static Map<String, Object> runEsqlAsync(RequestObjectBuilder requestObject, AssertWarnings assertWarnings) throws IOException {
|
|
|
addAsyncParameters(requestObject);
|
|
|
requestObject.build();
|
|
|
Request request = prepareRequest(ASYNC);
|
|
@@ -1089,7 +1075,7 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
assertThat(response.getHeader("X-Elasticsearch-Async-Id"), nullValue());
|
|
|
assertThat(response.getHeader("X-Elasticsearch-Async-Is-Running"), is("?0"));
|
|
|
}
|
|
|
- assertWarnings(response, expectedWarnings, expectedWarningsRegex);
|
|
|
+ assertWarnings(response, assertWarnings);
|
|
|
json.remove("is_running"); // remove this to not mess up later map assertions
|
|
|
return Collections.unmodifiableMap(json);
|
|
|
} else {
|
|
@@ -1099,7 +1085,7 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
if (isRunning == false) {
|
|
|
// must have completed immediately so keep_on_completion must be true
|
|
|
assertThat(requestObject.keepOnCompletion(), is(true));
|
|
|
- assertWarnings(response, expectedWarnings, expectedWarningsRegex);
|
|
|
+ assertWarnings(response, assertWarnings);
|
|
|
// we already have the results, but let's remember them so that we can compare to async get
|
|
|
initialColumns = json.get("columns");
|
|
|
initialValues = json.get("values");
|
|
@@ -1129,7 +1115,7 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
assertEquals(initialValues, result.get("values"));
|
|
|
}
|
|
|
|
|
|
- assertWarnings(response, expectedWarnings, expectedWarningsRegex);
|
|
|
+ assertWarnings(response, assertWarnings);
|
|
|
assertDeletable(id);
|
|
|
return removeAsyncProperties(result);
|
|
|
}
|
|
@@ -1203,7 +1189,7 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
}
|
|
|
request.setOptions(options);
|
|
|
|
|
|
- HttpEntity entity = performRequest(request, NO_WARNINGS, NO_WARNINGS_REGEX);
|
|
|
+ HttpEntity entity = performRequest(request, new AssertWarnings.NoWarnings());
|
|
|
return Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8));
|
|
|
}
|
|
|
|
|
@@ -1236,9 +1222,8 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
return mediaType;
|
|
|
}
|
|
|
|
|
|
- private static HttpEntity performRequest(Request request, List<String> allowedWarnings, List<Pattern> allowedWarningsRegex)
|
|
|
- throws IOException {
|
|
|
- return assertWarnings(performRequest(request), allowedWarnings, allowedWarningsRegex);
|
|
|
+ private static HttpEntity performRequest(Request request, AssertWarnings assertWarnings) throws IOException {
|
|
|
+ return assertWarnings(performRequest(request), assertWarnings);
|
|
|
}
|
|
|
|
|
|
private static Response performRequest(Request request) throws IOException {
|
|
@@ -1251,13 +1236,13 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
- private static HttpEntity assertWarnings(Response response, List<String> allowedWarnings, List<Pattern> allowedWarningsRegex) {
|
|
|
+ private static HttpEntity assertWarnings(Response response, AssertWarnings assertWarnings) {
|
|
|
List<String> warnings = new ArrayList<>(response.getWarnings());
|
|
|
warnings.removeAll(mutedWarnings());
|
|
|
if (shouldLog()) {
|
|
|
LOGGER.info("RESPONSE warnings (after muted)={}", warnings);
|
|
|
}
|
|
|
- EsqlTestUtils.assertWarnings(warnings, allowedWarnings, allowedWarningsRegex);
|
|
|
+ assertWarnings.assertWarnings(warnings);
|
|
|
return response.getEntity();
|
|
|
}
|
|
|
|