@@ -255,22 +255,26 @@ static CsvSpecReader.CsvTestCase convertToRemoteIndices(CsvSpecReader.CsvTestCas
255255 String [] parts = commands [0 ].split ("(?i)metadata" );
256256 assert parts .length >= 1 : parts ;
257257 String fromStatement = parts [0 ];
258- String index = fromStatement .substring ("FROM " .length ());
258+ String [] localIndices = fromStatement .substring ("FROM " .length ()).split ("," );
259+ final String remoteIndices ;
259260 if (canUseRemoteIndicesOnly () && randomBoolean ()) {
260- index = remoteIndices ( index );
261+ remoteIndices = Arrays . stream ( localIndices ). map ( index -> "*:" + index . trim ()). collect ( Collectors . joining ( "," ) );
261262 } else {
262- index = index + "," + remoteIndices (index );
263+ remoteIndices = Arrays .stream (localIndices )
264+ .map (index -> "*:" + index .trim () + "," + index .trim ())
265+ .collect (Collectors .joining ("," ));
263266 }
264- var newFrom = "FROM " + index + " " + commands [0 ].substring (fromStatement .length ());
267+ var newFrom = "FROM " + remoteIndices + " " + commands [0 ].substring (fromStatement .length ());
265268 testCase .query = newFrom + query .substring (first .length ());
266269 }
267270 if (commands [0 ].toLowerCase (Locale .ROOT ).startsWith ("ts " )) {
268271 String [] parts = commands [0 ].split ("\\ s+" );
269272 assert parts .length >= 2 : commands [0 ];
273+ String [] indices = parts [1 ].split ("," );
270274 if (canUseRemoteIndicesOnly () && randomBoolean ()) {
271- parts [1 ] = remoteIndices ( parts [ 1 ] );
275+ parts [1 ] = Arrays . stream ( indices ). map ( index -> "*:" + index . trim ()). collect ( Collectors . joining ( "," ) );
272276 } else {
273- parts [1 ] = parts [ 1 ] + "," + remoteIndices ( parts [ 1 ] );
277+ parts [1 ] = Arrays . stream ( indices ). map ( index -> "*:" + index . trim () + "," + index . trim ()). collect ( Collectors . joining ( "," ) );
274278 }
275279 String newNewMetrics = String .join (" " , parts );
276280 testCase .query = newNewMetrics + query .substring (first .length ());
@@ -288,12 +292,9 @@ static CsvSpecReader.CsvTestCase convertToRemoteIndices(CsvSpecReader.CsvTestCas
288292 return testCase ;
289293 }
290294
291- static String remoteIndices (String localIndices ) {
292- String [] parts = localIndices .split ("," );
293- return Arrays .stream (parts ).map (index -> "*:" + index .trim ()).collect (Collectors .joining ("," ));
294- }
295-
296295 static boolean canUseRemoteIndicesOnly () {
296+ // If the data is indexed only into the remote cluster, we can query only the remote indices.
297+ // However, due to the union types bug in CCS, we must include the local indices in versions without the fix.
297298 return dataLocation == DataLocation .REMOTE_ONLY && Clusters .bwcVersion ().onOrAfter (Version .V_9_1_0 );
298299 }
299300
0 commit comments