3232import org .elasticsearch .xpack .esql .index .IndexResolution ;
3333import org .elasticsearch .xpack .esql .plan .IndexPattern ;
3434import org .elasticsearch .xpack .esql .type .EsFieldTests ;
35+ import org .hamcrest .Matcher ;
3536
3637import java .util .ArrayList ;
3738import java .util .Arrays ;
3839import java .util .EnumSet ;
3940import java .util .HashMap ;
40- import java .util .HashSet ;
4141import java .util .List ;
4242import java .util .Locale ;
4343import java .util .Map ;
@@ -60,20 +60,16 @@ public class EsqlCCSUtilsTests extends ESTestCase {
6060 private final String REMOTE2_ALIAS = "remote2" ;
6161
6262 public void testCreateIndexExpressionFromAvailableClusters () {
63-
63+ var skipped = EsqlExecutionInfo . Cluster . Status . SKIPPED ;
6464 // no clusters marked as skipped
6565 {
6666 EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
6767 executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "logs*" , false ));
6868 executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*" , true ));
6969 executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "mylogs1,mylogs2,logs*" , true ));
70-
71- String indexExpr = EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo );
72- List <String > list = Arrays .stream (Strings .splitStringByCommaToArray (indexExpr )).toList ();
73- assertThat (list .size (), equalTo (5 ));
74- assertThat (
75- new HashSet <>(list ),
76- equalTo (Strings .commaDelimitedListToSet ("logs*,remote1:*,remote2:mylogs1,remote2:mylogs2,remote2:logs*" ))
70+ assertIndexPattern (
71+ EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ),
72+ containsInAnyOrder ("logs*" , "remote1:*" , "remote2:mylogs1" , "remote2:mylogs2" , "remote2:logs*" )
7773 );
7874 }
7975
@@ -84,38 +80,23 @@ public void testCreateIndexExpressionFromAvailableClusters() {
8480 executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo" , true ));
8581 executionInfo .swapCluster (
8682 REMOTE2_ALIAS ,
87- (k , v ) -> new EsqlExecutionInfo .Cluster (
88- REMOTE2_ALIAS ,
89- "mylogs1,mylogs2,logs*" ,
90- true ,
91- EsqlExecutionInfo .Cluster .Status .SKIPPED
92- )
83+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "mylogs1,mylogs2,logs*" , true , skipped )
84+ );
85+ assertIndexPattern (
86+ EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ),
87+ containsInAnyOrder ("logs*" , "remote1:*" , "remote1:foo" )
9388 );
94-
95- String indexExpr = EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo );
96- List <String > list = Arrays .stream (Strings .splitStringByCommaToArray (indexExpr )).toList ();
97- assertThat (list .size (), equalTo (3 ));
98- assertThat (new HashSet <>(list ), equalTo (Strings .commaDelimitedListToSet ("logs*,remote1:*,remote1:foo" )));
9989 }
10090
10191 // two clusters marked as skipped, so only local cluster present in revised index expression
10292 {
10393 EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
10494 executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "logs*" , false ));
105- executionInfo .swapCluster (
106- REMOTE1_ALIAS ,
107- (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo" , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
108- );
95+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo" , true , skipped ));
10996 executionInfo .swapCluster (
11097 REMOTE2_ALIAS ,
111- (k , v ) -> new EsqlExecutionInfo .Cluster (
112- REMOTE2_ALIAS ,
113- "mylogs1,mylogs2,logs*" ,
114- true ,
115- EsqlExecutionInfo .Cluster .Status .SKIPPED
116- )
98+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "mylogs1,mylogs2,logs*" , true , skipped )
11799 );
118-
119100 assertThat (EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ), equalTo ("logs*" ));
120101 }
121102
@@ -128,18 +109,64 @@ public void testCreateIndexExpressionFromAvailableClusters() {
128109 );
129110 executionInfo .swapCluster (
130111 REMOTE2_ALIAS ,
131- (k , v ) -> new EsqlExecutionInfo .Cluster (
132- REMOTE2_ALIAS ,
133- "mylogs1,mylogs2,logs*" ,
134- true ,
135- EsqlExecutionInfo .Cluster .Status .SKIPPED
136- )
112+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "mylogs1,mylogs2,logs*" , true , skipped )
137113 );
138-
139114 assertThat (EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ), equalTo ("" ));
140115 }
141116 }
142117
118+ public void testCreateQualifiedLookupIndexExpressionFromAvailableClusters () {
119+
120+ var skipped = EsqlExecutionInfo .Cluster .Status .SKIPPED ;
121+ // no clusters marked as skipped
122+ {
123+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
124+ executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "" , false ));
125+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true ));
126+ executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true ));
127+ assertIndexPattern (
128+ EsqlCCSUtils .createQualifiedLookupIndexExpressionFromAvailableClusters (executionInfo , "lookup" ),
129+ containsInAnyOrder ("lookup" , REMOTE1_ALIAS + ":lookup" , REMOTE2_ALIAS + ":lookup" )
130+ );
131+ }
132+ // one cluster marked as skipped
133+ {
134+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
135+ executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "" , false ));
136+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true ));
137+ executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true , skipped ));
138+ assertIndexPattern (
139+ EsqlCCSUtils .createQualifiedLookupIndexExpressionFromAvailableClusters (executionInfo , "lookup" ),
140+ containsInAnyOrder ("lookup" , REMOTE1_ALIAS + ":lookup" )
141+ );
142+ }
143+ // all remotes marked as skipped
144+ {
145+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
146+ executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "" , false ));
147+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true , skipped ));
148+ executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true , skipped ));
149+ assertIndexPattern (
150+ EsqlCCSUtils .createQualifiedLookupIndexExpressionFromAvailableClusters (executionInfo , "lookup" ),
151+ containsInAnyOrder ("lookup" )
152+ );
153+ }
154+ // all remotes are skipped and no local
155+ {
156+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
157+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true , skipped ));
158+ executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true , skipped ));
159+ assertIndexPattern (
160+ EsqlCCSUtils .createQualifiedLookupIndexExpressionFromAvailableClusters (executionInfo , "lookup" ),
161+ containsInAnyOrder ()
162+ );
163+ }
164+ }
165+
166+ private static void assertIndexPattern (String indexPattern , Matcher <Iterable <? extends String >> matcher ) {
167+ assertThat (Set .of (Strings .splitStringByCommaToArray (indexPattern )), matcher );
168+ }
169+
143170 public void testUpdateExecutionInfoWithUnavailableClusters () {
144171
145172 // skip_unavailable=true clusters are unavailable, both marked as SKIPPED
@@ -806,5 +833,4 @@ public Map<String, OriginalIndices> groupIndices(
806833 return originalIndicesMap ;
807834 }
808835 }
809-
810836}
0 commit comments