77
88package org .elasticsearch .xpack .esql .plugin ;
99
10+ import org .elasticsearch .action .admin .indices .template .put .TransportPutComposableIndexTemplateAction ;
11+ import org .elasticsearch .action .datastreams .CreateDataStreamAction ;
1012import org .elasticsearch .cluster .block .ClusterBlockException ;
13+ import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
14+ import org .elasticsearch .common .util .CollectionUtils ;
15+ import org .elasticsearch .datastreams .DataStreamsPlugin ;
16+ import org .elasticsearch .index .IndexNotFoundException ;
17+ import org .elasticsearch .plugins .Plugin ;
1118import org .elasticsearch .xpack .esql .VerificationException ;
1219import org .elasticsearch .xpack .esql .action .AbstractEsqlIntegTestCase ;
1320import org .elasticsearch .xpack .esql .action .EsqlQueryResponse ;
1421
22+ import java .util .Collection ;
23+ import java .util .List ;
24+
1525import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
1626import static org .elasticsearch .xpack .esql .action .EsqlQueryRequest .syncEsqlQueryRequest ;
1727import static org .hamcrest .Matchers .containsString ;
1828import static org .hamcrest .Matchers .equalTo ;
1929
2030public class IndexResolutionIT extends AbstractEsqlIntegTestCase {
2131
32+ @ Override
33+ protected Collection <Class <? extends Plugin >> nodePlugins () {
34+ return CollectionUtils .appendToCopy (super .nodePlugins (), DataStreamsPlugin .class );
35+ }
36+
2237 public void testResolvesConcreteIndex () {
2338 assertAcked (client ().admin ().indices ().prepareCreate ("index-1" ));
2439 indexRandom (true , "index-1" , 10 );
@@ -39,7 +54,27 @@ public void testResolvesAlias() {
3954 }
4055
4156 public void testResolvesDataStream () {
42- // TODO
57+ assertAcked (
58+ client ().execute (
59+ TransportPutComposableIndexTemplateAction .TYPE ,
60+ new TransportPutComposableIndexTemplateAction .Request ("data-stream-1-template" ).indexTemplate (
61+ ComposableIndexTemplate .builder ()
62+ .indexPatterns (List .of ("data-stream-1*" ))
63+ .dataStreamTemplate (new ComposableIndexTemplate .DataStreamTemplate ())
64+ .build ()
65+ )
66+ )
67+ );
68+ assertAcked (
69+ client ().execute (
70+ CreateDataStreamAction .INSTANCE ,
71+ new CreateDataStreamAction .Request (TEST_REQUEST_TIMEOUT , TEST_REQUEST_TIMEOUT , "data-stream-1" )
72+ )
73+ );
74+
75+ try (var response = run (syncEsqlQueryRequest ().query ("FROM data-stream-1" ))) {
76+ assertOk (response );
77+ }
4378 }
4479
4580 public void testResolvesPattern () {
@@ -82,7 +117,18 @@ public void testDoesNotResolveClosedIndex() {
82117 }
83118
84119 public void testPartialResolution () {
85- // TODO
120+ assertAcked (client ().admin ().indices ().prepareCreate ("index-1" ));
121+ assertAcked (client ().admin ().indices ().prepareCreate ("index-2" ));
122+ indexRandom (true , "index-2" , 10 );
123+
124+ try (var response = run (syncEsqlQueryRequest ().query ("FROM index-1,nonexisting" ))) {
125+ assertOk (response );
126+ }
127+ expectThrows (
128+ IndexNotFoundException .class ,
129+ equalTo ("no such index [nonexisting]" ),
130+ () -> run (syncEsqlQueryRequest ().query ("FROM index-2,nonexisting" ))
131+ );
86132 }
87133
88134 private static void assertOk (EsqlQueryResponse response ) {
0 commit comments