32
32
import org .elasticsearch .xpack .esql .index .IndexResolution ;
33
33
import org .elasticsearch .xpack .esql .plan .IndexPattern ;
34
34
import org .elasticsearch .xpack .esql .type .EsFieldTests ;
35
+ import org .hamcrest .Matcher ;
35
36
36
37
import java .util .ArrayList ;
37
38
import java .util .Arrays ;
38
39
import java .util .EnumSet ;
39
40
import java .util .HashMap ;
40
- import java .util .HashSet ;
41
41
import java .util .List ;
42
42
import java .util .Locale ;
43
43
import java .util .Map ;
@@ -60,20 +60,16 @@ public class EsqlCCSUtilsTests extends ESTestCase {
60
60
private final String REMOTE2_ALIAS = "remote2" ;
61
61
62
62
public void testCreateIndexExpressionFromAvailableClusters () {
63
-
63
+ var skipped = EsqlExecutionInfo . Cluster . Status . SKIPPED ;
64
64
// no clusters marked as skipped
65
65
{
66
66
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
67
67
executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "logs*" , false ));
68
68
executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*" , true ));
69
69
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*" )
77
73
);
78
74
}
79
75
@@ -84,38 +80,23 @@ public void testCreateIndexExpressionFromAvailableClusters() {
84
80
executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo" , true ));
85
81
executionInfo .swapCluster (
86
82
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" )
93
88
);
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" )));
99
89
}
100
90
101
91
// two clusters marked as skipped, so only local cluster present in revised index expression
102
92
{
103
93
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
104
94
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 ));
109
96
executionInfo .swapCluster (
110
97
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 )
117
99
);
118
-
119
100
assertThat (EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ), equalTo ("logs*" ));
120
101
}
121
102
@@ -128,18 +109,64 @@ public void testCreateIndexExpressionFromAvailableClusters() {
128
109
);
129
110
executionInfo .swapCluster (
130
111
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 )
137
113
);
138
-
139
114
assertThat (EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ), equalTo ("" ));
140
115
}
141
116
}
142
117
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
+
143
170
public void testUpdateExecutionInfoWithUnavailableClusters () {
144
171
145
172
// skip_unavailable=true clusters are unavailable, both marked as SKIPPED
@@ -806,5 +833,4 @@ public Map<String, OriginalIndices> groupIndices(
806
833
return originalIndicesMap ;
807
834
}
808
835
}
809
-
810
836
}
0 commit comments