Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.xpack.esql.ccq.Clusters.REMOTE_CLUSTER_NAME;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.any;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasKey;

@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
public class MultiClustersIT extends ESRestTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.test.MapMatcher;
import org.elasticsearch.test.TestClustersThreadFilter;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.xpack.esql.qa.rest.RequestIndexFilteringTestCase;
import org.elasticsearch.xpack.esql.qa.rest.RestEsqlTestCase;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -27,6 +30,12 @@
import org.junit.rules.TestRule;

import java.io.IOException;
import java.util.Map;

import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.MapMatcher.matchesMap;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;

@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
public class RequestIndexFilteringIT extends RequestIndexFilteringTestCase {
Expand All @@ -51,6 +60,8 @@ public void setRemoteClient() throws IOException {
}
}

private boolean isCCSRequest;

@BeforeClass
public static void checkVersion() {
assumeTrue("skip if version before 8.18", Clusters.localClusterVersion().onOrAfter(Version.V_8_18_0));
Expand All @@ -73,13 +84,20 @@ protected void indexTimestampData(int docs, String indexName, String date, Strin

@Override
protected String from(String... indexName) {
if (randomBoolean()) {
isCCSRequest = randomBoolean();
if (isCCSRequest) {
return "FROM *:" + String.join(",*:", indexName);
} else {
return "FROM " + String.join(",", indexName);
}
}

@Override
public Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder requestObject) throws IOException {
requestObject.includeCCSMetadata(true);
return super.runEsql(requestObject);
}

@After
public void wipeRemoteTestData() throws IOException {
try {
Expand All @@ -89,4 +107,35 @@ public void wipeRemoteTestData() throws IOException {
assertEquals(404, re.getResponse().getStatusLine().getStatusCode());
}
}

private MapMatcher getClustersMetadataMatcher() {
MapMatcher mapMatcher = matchesMap();
mapMatcher = mapMatcher.entry("running", 0);
mapMatcher = mapMatcher.entry("total", 1);
mapMatcher = mapMatcher.entry("failed", 0);
mapMatcher = mapMatcher.entry("partial", 0);
mapMatcher = mapMatcher.entry("successful", 1);
mapMatcher = mapMatcher.entry("skipped", 0);
mapMatcher = mapMatcher.entry(
"details",
matchesMap().entry(
Clusters.REMOTE_CLUSTER_NAME,
matchesMap().entry("_shards", matchesMap().extraOk())
.entry("took", greaterThanOrEqualTo(0))
.entry("indices", instanceOf(String.class))
.entry("status", "successful")
)
);
return mapMatcher;
}

@Override
protected void assertQueryResult(Map<String, Object> result, Matcher<?> columnMatcher, Matcher<?> valuesMatcher) {
var matcher = getResultMatcher(result).entry("columns", columnMatcher).entry("values", valuesMatcher);
if (isCCSRequest) {
matcher = matcher.entry("_clusters", getClustersMetadataMatcher());
}
assertMap(result, matcher);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.esql.AssertWarnings;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Assert;

Expand Down Expand Up @@ -62,7 +63,7 @@ public void testTimestampFilterFromQuery() throws IOException {

// filter includes both indices in the result (all columns, all rows)
RestEsqlTestCase.RequestObjectBuilder builder = timestampFilter("gte", "2023-01-01").query(from("test*"));
assertResultMap(
assertQueryResult(
runEsql(builder),
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
Expand All @@ -73,7 +74,7 @@ public void testTimestampFilterFromQuery() throws IOException {

// filter includes only test1. Columns from test2 are filtered out, as well (not only rows)!
builder = timestampFilter("gte", "2024-01-01").query(from("test*"));
assertResultMap(
assertQueryResult(
runEsql(builder),
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
Expand All @@ -84,7 +85,7 @@ public void testTimestampFilterFromQuery() throws IOException {
// filter excludes both indices (no rows); the first analysis step fails because there are no columns, a second attempt succeeds
// after eliminating the index filter. All columns are returned.
builder = timestampFilter("gte", "2025-01-01").query(from("test*"));
assertResultMap(
assertQueryResult(
runEsql(builder),
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
Expand All @@ -102,7 +103,7 @@ public void testFieldExistsFilter_KeepWildcard() throws IOException {

// filter includes only test1. Columns and rows of test2 are filtered out
RestEsqlTestCase.RequestObjectBuilder builder = existsFilter("id1").query(from("test*"));
assertResultMap(
assertQueryResult(
runEsql(builder),
matchesList().item(matchesMap().entry("name", "@timestamp").entry("type", "date"))
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
Expand All @@ -113,7 +114,7 @@ public void testFieldExistsFilter_KeepWildcard() throws IOException {
// filter includes only test1. Columns from test2 are filtered out, as well (not only rows)!
builder = existsFilter("id1").query(from("test*") + " METADATA _index | KEEP _index, id*");
Map<String, Object> result = runEsql(builder);
assertResultMap(
assertQueryResult(
result,
matchesList().item(matchesMap().entry("name", "_index").entry("type", "keyword"))
.item(matchesMap().entry("name", "id1").entry("type", "integer")),
Expand All @@ -138,7 +139,7 @@ public void testFieldExistsFilter_With_ExplicitUseOfDiscardedIndexFields() throw
from("test*") + " METADATA _index | SORT id2 | KEEP _index, id*"
);
Map<String, Object> result = runEsql(builder);
assertResultMap(
assertQueryResult(
result,
matchesList().item(matchesMap().entry("name", "_index").entry("type", "keyword"))
.item(matchesMap().entry("name", "id1").entry("type", "integer"))
Expand Down Expand Up @@ -298,4 +299,9 @@ protected void indexTimestampDataForClient(RestClient client, int docs, String i
Assert.assertEquals("{\"errors\":false}", EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8));
}
}

protected void assertQueryResult(Map<String, Object> result, Matcher<?> columnMatcher, Matcher<?> valuesMatcher) {
assertResultMap(result, columnMatcher, valuesMatcher);
}

}