@@ -127,8 +127,18 @@ void indexDocs(RestClient client, String index, List<Doc> docs) throws IOExcepti
127
127
refresh (client , index );
128
128
}
129
129
130
- private Map <String , Object > run (String query ) throws IOException {
131
- Map <String , Object > resp = runEsql (new RestEsqlTestCase .RequestObjectBuilder ().query (query ).build ());
130
+ private Map <String , Object > run (String query , boolean includeCCSMetadata ) throws IOException {
131
+ Map <String , Object > resp = runEsql (
132
+ new RestEsqlTestCase .RequestObjectBuilder ().query (query ).includeCCSMetadata (includeCCSMetadata ).build ()
133
+ );
134
+ logger .info ("--> query {} response {}" , query , resp );
135
+ return resp ;
136
+ }
137
+
138
+ private Map <String , Object > runWithColumnarAndIncludeCCSMetadata (String query ) throws IOException {
139
+ Map <String , Object > resp = runEsql (
140
+ new RestEsqlTestCase .RequestObjectBuilder ().query (query ).includeCCSMetadata (true ).columnar (true ).build ()
141
+ );
132
142
logger .info ("--> query {} response {}" , query , resp );
133
143
return resp ;
134
144
}
@@ -147,62 +157,77 @@ private Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder reques
147
157
148
158
public void testCount () throws Exception {
149
159
{
150
- Map <String , Object > result = run ("FROM test-local-index,*:test-remote-index | STATS c = COUNT(*)" );
160
+ boolean includeCCSMetadata = randomBoolean ();
161
+ Map <String , Object > result = run ("FROM test-local-index,*:test-remote-index | STATS c = COUNT(*)" , includeCCSMetadata );
151
162
var columns = List .of (Map .of ("name" , "c" , "type" , "long" ));
152
163
var values = List .of (List .of (localDocs .size () + remoteDocs .size ()));
153
164
154
165
MapMatcher mapMatcher = matchesMap ();
155
- assertMap (
156
- result ,
157
- mapMatcher .entry ("columns" , columns )
158
- .entry ("values" , values )
159
- .entry ("took" , greaterThanOrEqualTo (0 ))
160
- .entry ("_clusters" , any (Map .class ))
161
- );
162
- assertClusterDetailsMap (result , false );
166
+ if (includeCCSMetadata ) {
167
+ mapMatcher = mapMatcher .entry ("_clusters" , any (Map .class ));
168
+ }
169
+ assertMap (result , mapMatcher .entry ("columns" , columns ).entry ("values" , values ).entry ("took" , greaterThanOrEqualTo (0 )));
170
+ if (includeCCSMetadata ) {
171
+ assertClusterDetailsMap (result , false );
172
+ }
163
173
}
164
174
{
165
- Map <String , Object > result = run ("FROM *:test-remote-index | STATS c = COUNT(*)" );
175
+ boolean includeCCSMetadata = randomBoolean ();
176
+ Map <String , Object > result = run ("FROM *:test-remote-index | STATS c = COUNT(*)" , includeCCSMetadata );
166
177
var columns = List .of (Map .of ("name" , "c" , "type" , "long" ));
167
178
var values = List .of (List .of (remoteDocs .size ()));
168
179
169
180
MapMatcher mapMatcher = matchesMap ();
170
- assertMap (
171
- result ,
172
- mapMatcher .entry ("columns" , columns )
173
- .entry ("values" , values )
174
- .entry ("took" , greaterThanOrEqualTo (0 ))
175
- .entry ("_clusters" , any (Map .class ))
176
- );
177
- assertClusterDetailsMap (result , true );
181
+ if (includeCCSMetadata ) {
182
+ mapMatcher = mapMatcher .entry ("_clusters" , any (Map .class ));
183
+ }
184
+ assertMap (result , mapMatcher .entry ("columns" , columns ).entry ("values" , values ).entry ("took" , greaterThanOrEqualTo (0 )));
185
+ if (includeCCSMetadata ) {
186
+ assertClusterDetailsMap (result , true );
187
+ }
178
188
}
179
189
}
180
190
181
191
public void testUngroupedAggs () throws Exception {
182
192
{
183
- Map <String , Object > result = run ("FROM test-local-index,*:test-remote-index | STATS total = SUM(data)" );
193
+ boolean includeCCSMetadata = randomBoolean ();
194
+ Map <String , Object > result = run ("FROM test-local-index,*:test-remote-index | STATS total = SUM(data)" , includeCCSMetadata );
184
195
var columns = List .of (Map .of ("name" , "total" , "type" , "long" ));
185
196
long sum = Stream .concat (localDocs .stream (), remoteDocs .stream ()).mapToLong (d -> d .data ).sum ();
186
197
var values = List .of (List .of (Math .toIntExact (sum )));
187
198
188
199
// check all sections of map except _cluster/details
189
200
MapMatcher mapMatcher = matchesMap ();
190
- assertMap (
191
- result ,
192
- mapMatcher .entry ("columns" , columns )
193
- .entry ("values" , values )
194
- .entry ("took" , greaterThanOrEqualTo (0 ))
195
- .entry ("_clusters" , any (Map .class ))
196
- );
197
- assertClusterDetailsMap (result , false );
201
+ if (includeCCSMetadata ) {
202
+ mapMatcher = mapMatcher .entry ("_clusters" , any (Map .class ));
203
+ }
204
+ assertMap (result , mapMatcher .entry ("columns" , columns ).entry ("values" , values ).entry ("took" , greaterThanOrEqualTo (0 )));
205
+ if (includeCCSMetadata ) {
206
+ assertClusterDetailsMap (result , false );
207
+ }
198
208
}
199
209
{
200
- Map <String , Object > result = run ("FROM *:test-remote-index | STATS total = SUM(data)" );
210
+ boolean includeCCSMetadata = randomBoolean ();
211
+ Map <String , Object > result = run ("FROM *:test-remote-index | STATS total = SUM(data)" , includeCCSMetadata );
212
+ var columns = List .of (Map .of ("name" , "total" , "type" , "long" ));
213
+ long sum = remoteDocs .stream ().mapToLong (d -> d .data ).sum ();
214
+ var values = List .of (List .of (Math .toIntExact (sum )));
215
+
216
+ MapMatcher mapMatcher = matchesMap ();
217
+ if (includeCCSMetadata ) {
218
+ mapMatcher = mapMatcher .entry ("_clusters" , any (Map .class ));
219
+ }
220
+ assertMap (result , mapMatcher .entry ("columns" , columns ).entry ("values" , values ).entry ("took" , greaterThanOrEqualTo (0 )));
221
+ if (includeCCSMetadata ) {
222
+ assertClusterDetailsMap (result , true );
223
+ }
224
+ }
225
+ {
226
+ Map <String , Object > result = runWithColumnarAndIncludeCCSMetadata ("FROM *:test-remote-index | STATS total = SUM(data)" );
201
227
var columns = List .of (Map .of ("name" , "total" , "type" , "long" ));
202
228
long sum = remoteDocs .stream ().mapToLong (d -> d .data ).sum ();
203
229
var values = List .of (List .of (Math .toIntExact (sum )));
204
230
205
- // check all sections of map except _cluster/details
206
231
MapMatcher mapMatcher = matchesMap ();
207
232
assertMap (
208
233
result ,
@@ -269,7 +294,11 @@ private void assertClusterDetailsMap(Map<String, Object> result, boolean remoteO
269
294
270
295
public void testGroupedAggs () throws Exception {
271
296
{
272
- Map <String , Object > result = run ("FROM test-local-index,*:test-remote-index | STATS total = SUM(data) BY color | SORT color" );
297
+ boolean includeCCSMetadata = randomBoolean ();
298
+ Map <String , Object > result = run (
299
+ "FROM test-local-index,*:test-remote-index | STATS total = SUM(data) BY color | SORT color" ,
300
+ includeCCSMetadata
301
+ );
273
302
var columns = List .of (Map .of ("name" , "total" , "type" , "long" ), Map .of ("name" , "color" , "type" , "keyword" ));
274
303
var values = Stream .concat (localDocs .stream (), remoteDocs .stream ())
275
304
.collect (Collectors .toMap (d -> d .color , Doc ::data , Long ::sum ))
@@ -280,17 +309,20 @@ public void testGroupedAggs() throws Exception {
280
309
.toList ();
281
310
282
311
MapMatcher mapMatcher = matchesMap ();
283
- assertMap (
284
- result ,
285
- mapMatcher .entry ("columns" , columns )
286
- .entry ("values" , values )
287
- .entry ("took" , greaterThanOrEqualTo (0 ))
288
- .entry ("_clusters" , any (Map .class ))
289
- );
290
- assertClusterDetailsMap (result , false );
312
+ if (includeCCSMetadata ) {
313
+ mapMatcher = mapMatcher .entry ("_clusters" , any (Map .class ));
314
+ }
315
+ assertMap (result , mapMatcher .entry ("columns" , columns ).entry ("values" , values ).entry ("took" , greaterThanOrEqualTo (0 )));
316
+ if (includeCCSMetadata ) {
317
+ assertClusterDetailsMap (result , false );
318
+ }
291
319
}
292
320
{
293
- Map <String , Object > result = run ("FROM *:test-remote-index | STATS total = SUM(data) by color | SORT color" );
321
+ boolean includeCCSMetadata = randomBoolean ();
322
+ Map <String , Object > result = run (
323
+ "FROM *:test-remote-index | STATS total = SUM(data) by color | SORT color" ,
324
+ includeCCSMetadata
325
+ );
294
326
var columns = List .of (Map .of ("name" , "total" , "type" , "long" ), Map .of ("name" , "color" , "type" , "keyword" ));
295
327
var values = remoteDocs .stream ()
296
328
.collect (Collectors .toMap (d -> d .color , Doc ::data , Long ::sum ))
@@ -300,16 +332,15 @@ public void testGroupedAggs() throws Exception {
300
332
.map (e -> List .of (Math .toIntExact (e .getValue ()), e .getKey ()))
301
333
.toList ();
302
334
303
- // check all sections of map except _cluster /details
335
+ // check all sections of map except _clusters /details
304
336
MapMatcher mapMatcher = matchesMap ();
305
- assertMap (
306
- result ,
307
- mapMatcher .entry ("columns" , columns )
308
- .entry ("values" , values )
309
- .entry ("took" , greaterThanOrEqualTo (0 ))
310
- .entry ("_clusters" , any (Map .class ))
311
- );
312
- assertClusterDetailsMap (result , true );
337
+ if (includeCCSMetadata ) {
338
+ mapMatcher = mapMatcher .entry ("_clusters" , any (Map .class ));
339
+ }
340
+ assertMap (result , mapMatcher .entry ("columns" , columns ).entry ("values" , values ).entry ("took" , greaterThanOrEqualTo (0 )));
341
+ if (includeCCSMetadata ) {
342
+ assertClusterDetailsMap (result , true );
343
+ }
313
344
}
314
345
}
315
346
0 commit comments