|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.esql.plugin; |
9 | 9 |
|
| 10 | +import org.elasticsearch.action.bulk.BulkRequestBuilder; |
10 | 11 | import org.elasticsearch.action.index.IndexRequest; |
11 | 12 | import org.elasticsearch.action.support.WriteRequest; |
12 | 13 | import org.elasticsearch.cluster.metadata.IndexMetadata; |
|
17 | 18 | import org.elasticsearch.index.query.RangeQueryBuilder; |
18 | 19 | import org.elasticsearch.index.shard.ShardId; |
19 | 20 | import org.elasticsearch.plugins.Plugin; |
| 21 | +import org.elasticsearch.tasks.Task; |
20 | 22 | import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; |
21 | 23 | import org.elasticsearch.test.transport.MockTransportService; |
| 24 | +import org.elasticsearch.test.transport.StubbableTransport; |
| 25 | +import org.elasticsearch.transport.TransportChannel; |
| 26 | +import org.elasticsearch.transport.TransportRequest; |
| 27 | +import org.elasticsearch.transport.TransportRequestHandler; |
22 | 28 | import org.elasticsearch.transport.TransportService; |
23 | 29 | import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase; |
24 | 30 | import org.elasticsearch.xpack.esql.action.EsqlQueryResponse; |
25 | 31 |
|
26 | 32 | import java.util.Collection; |
| 33 | +import java.util.HashMap; |
27 | 34 | import java.util.List; |
| 35 | +import java.util.Map; |
28 | 36 | import java.util.Set; |
29 | 37 |
|
| 38 | +import static org.elasticsearch.xpack.esql.EsqlTestUtils.as; |
30 | 39 | import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList; |
31 | 40 | import static org.hamcrest.Matchers.containsString; |
32 | 41 | import static org.hamcrest.Matchers.empty; |
@@ -250,4 +259,61 @@ public void testFailOnUnavailableShards() throws Exception { |
250 | 259 | assertThat(error.getMessage(), containsString("no shard copies found")); |
251 | 260 | } |
252 | 261 | } |
| 262 | + |
| 263 | + public void testSkipOnIndexName() { |
| 264 | + internalCluster().ensureAtLeastNumDataNodes(2); |
| 265 | + int numIndices = between(2, 10); |
| 266 | + Map<String, Integer> indexToNumDocs = new HashMap<>(); |
| 267 | + for (int i = 0; i < numIndices; i++) { |
| 268 | + String index = "events-" + i; |
| 269 | + ElasticsearchAssertions.assertAcked( |
| 270 | + client().admin().indices().prepareCreate(index).setMapping("timestamp", "type=long", "message", "type=keyword") |
| 271 | + ); |
| 272 | + BulkRequestBuilder bulk = client().prepareBulk(index).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); |
| 273 | + int docs = between(1, 5); |
| 274 | + long timestamp = 1; |
| 275 | + for (int d = 0; d < docs; d++) { |
| 276 | + bulk.add(new IndexRequest().source("timestamp", ++timestamp, "message", "v-" + d)); |
| 277 | + } |
| 278 | + bulk.get(); |
| 279 | + indexToNumDocs.put(index, docs); |
| 280 | + } |
| 281 | + Set<String> queriedIndices = ConcurrentCollections.newConcurrentSet(); |
| 282 | + for (TransportService ts : internalCluster().getInstances(TransportService.class)) { |
| 283 | + MockTransportService mockTransportService = as(ts, MockTransportService.class); |
| 284 | + mockTransportService.addRequestHandlingBehavior( |
| 285 | + ComputeService.DATA_ACTION_NAME, |
| 286 | + new StubbableTransport.RequestHandlingBehavior<TransportRequest>() { |
| 287 | + @Override |
| 288 | + public void messageReceived( |
| 289 | + TransportRequestHandler<TransportRequest> handler, |
| 290 | + TransportRequest request, |
| 291 | + TransportChannel channel, |
| 292 | + Task task |
| 293 | + ) throws Exception { |
| 294 | + DataNodeRequest dataNodeRequest = (DataNodeRequest) request; |
| 295 | + for (ShardId shardId : dataNodeRequest.shardIds()) { |
| 296 | + queriedIndices.add(shardId.getIndexName()); |
| 297 | + } |
| 298 | + handler.messageReceived(request, channel, task); |
| 299 | + } |
| 300 | + } |
| 301 | + ); |
| 302 | + } |
| 303 | + try { |
| 304 | + for (int i = 0; i < numIndices; i++) { |
| 305 | + queriedIndices.clear(); |
| 306 | + String index = "events-" + i; |
| 307 | + try (EsqlQueryResponse resp = run("from events* METADATA _index | WHERE _index == \"" + index + "\" | KEEP timestamp")) { |
| 308 | + assertThat(getValuesList(resp), hasSize(indexToNumDocs.get(index))); |
| 309 | + } |
| 310 | + assertThat(queriedIndices, equalTo(Set.of(index))); |
| 311 | + } |
| 312 | + } finally { |
| 313 | + for (TransportService ts : internalCluster().getInstances(TransportService.class)) { |
| 314 | + MockTransportService mockTransportService = as(ts, MockTransportService.class); |
| 315 | + mockTransportService.clearAllRules(); |
| 316 | + } |
| 317 | + } |
| 318 | + } |
253 | 319 | } |
0 commit comments