@@ -127,8 +127,18 @@ void indexDocs(RestClient client, String index, List<Doc> docs) throws IOExcepti
127127 refresh (client , index );
128128 }
129129
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+ );
132142 logger .info ("--> query {} response {}" , query , resp );
133143 return resp ;
134144 }
@@ -147,62 +157,77 @@ private Map<String, Object> runEsql(RestEsqlTestCase.RequestObjectBuilder reques
147157
148158 public void testCount () throws Exception {
149159 {
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 );
151162 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ));
152163 var values = List .of (List .of (localDocs .size () + remoteDocs .size ()));
153164
154165 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+ }
163173 }
164174 {
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 );
166177 var columns = List .of (Map .of ("name" , "c" , "type" , "long" ));
167178 var values = List .of (List .of (remoteDocs .size ()));
168179
169180 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+ }
178188 }
179189 }
180190
181191 public void testUngroupedAggs () throws Exception {
182192 {
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 );
184195 var columns = List .of (Map .of ("name" , "total" , "type" , "long" ));
185196 long sum = Stream .concat (localDocs .stream (), remoteDocs .stream ()).mapToLong (d -> d .data ).sum ();
186197 var values = List .of (List .of (Math .toIntExact (sum )));
187198
188199 // check all sections of map except _cluster/details
189200 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+ }
198208 }
199209 {
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)" );
201227 var columns = List .of (Map .of ("name" , "total" , "type" , "long" ));
202228 long sum = remoteDocs .stream ().mapToLong (d -> d .data ).sum ();
203229 var values = List .of (List .of (Math .toIntExact (sum )));
204230
205- // check all sections of map except _cluster/details
206231 MapMatcher mapMatcher = matchesMap ();
207232 assertMap (
208233 result ,
@@ -269,7 +294,11 @@ private void assertClusterDetailsMap(Map<String, Object> result, boolean remoteO
269294
270295 public void testGroupedAggs () throws Exception {
271296 {
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+ );
273302 var columns = List .of (Map .of ("name" , "total" , "type" , "long" ), Map .of ("name" , "color" , "type" , "keyword" ));
274303 var values = Stream .concat (localDocs .stream (), remoteDocs .stream ())
275304 .collect (Collectors .toMap (d -> d .color , Doc ::data , Long ::sum ))
@@ -280,17 +309,20 @@ public void testGroupedAggs() throws Exception {
280309 .toList ();
281310
282311 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+ }
291319 }
292320 {
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+ );
294326 var columns = List .of (Map .of ("name" , "total" , "type" , "long" ), Map .of ("name" , "color" , "type" , "keyword" ));
295327 var values = remoteDocs .stream ()
296328 .collect (Collectors .toMap (d -> d .color , Doc ::data , Long ::sum ))
@@ -300,16 +332,15 @@ public void testGroupedAggs() throws Exception {
300332 .map (e -> List .of (Math .toIntExact (e .getValue ()), e .getKey ()))
301333 .toList ();
302334
303- // check all sections of map except _cluster /details
335+ // check all sections of map except _clusters /details
304336 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+ }
313344 }
314345 }
315346
0 commit comments