Skip to content

Commit 188f258

Browse files
ivanceaelasticsearchmachine
andauthored
ESQL: Fix multi cluster tests not working with @repeat (elastic#135208)
* ESQL: Fix multi cluster tests not working with @repeat * [CI] Auto commit changes from spotless * Keep original command casing * [CI] Update transport version definitions --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 96a20d2 commit 188f258

File tree

1 file changed

+24
-25
lines changed
  • x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq

1 file changed

+24
-25
lines changed

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -302,33 +302,32 @@ static CsvSpecReader.CsvTestCase convertToRemoteIndices(CsvSpecReader.CsvTestCas
302302
String first = commands[0].trim();
303303
// If true, we're using *:index, otherwise we're using *:index,index
304304
boolean onlyRemotes = canUseRemoteIndicesOnly() && randomBoolean();
305-
if (commands[0].toLowerCase(Locale.ROOT).startsWith("from")) {
306-
String[] parts = commands[0].split("(?i)metadata");
307-
assert parts.length >= 1 : parts;
308-
String fromStatement = parts[0];
309-
String[] localIndices = fromStatement.substring("FROM ".length()).split(",");
310-
if (Arrays.stream(localIndices).anyMatch(i -> LOOKUP_INDICES.contains(i.trim().toLowerCase(Locale.ROOT)))) {
311-
// If the query contains lookup indices, use only remotes to avoid duplication
312-
onlyRemotes = true;
305+
String[] commandParts = first.split("\\s+", 2);
306+
String command = commandParts[0].trim();
307+
if (command.equalsIgnoreCase("from") || command.equalsIgnoreCase("ts")) {
308+
String[] indexMetadataParts = commandParts[1].split("(?i)\\bmetadata\\b", 2);
309+
String indicesString = indexMetadataParts[0];
310+
String[] indices = indicesString.split(",");
311+
// This method may be called multiple times on the same testcase when using @Repeat
312+
boolean alreadyConverted = Arrays.stream(indices).anyMatch(i -> i.trim().startsWith("*:"));
313+
if (alreadyConverted == false) {
314+
if (Arrays.stream(indices).anyMatch(i -> LOOKUP_INDICES.contains(i.trim().toLowerCase(Locale.ROOT)))) {
315+
// If the query contains lookup indices, use only remotes to avoid duplication
316+
onlyRemotes = true;
317+
}
318+
final boolean onlyRemotesFinal = onlyRemotes;
319+
final String remoteIndices = Arrays.stream(indices)
320+
.map(index -> unquoteAndRequoteAsRemote(index.trim(), onlyRemotesFinal))
321+
.collect(Collectors.joining(","));
322+
String newFirstCommand = command
323+
+ " "
324+
+ remoteIndices
325+
+ " "
326+
+ (indexMetadataParts.length == 1 ? "" : "metadata " + indexMetadataParts[1]);
327+
testCase.query = newFirstCommand + query.substring(first.length());
313328
}
314-
final boolean onlyRemotesFinal = onlyRemotes;
315-
final String remoteIndices = Arrays.stream(localIndices)
316-
.map(index -> unquoteAndRequoteAsRemote(index.trim(), onlyRemotesFinal))
317-
.collect(Collectors.joining(","));
318-
var newFrom = "FROM " + remoteIndices + " " + commands[0].substring(fromStatement.length());
319-
testCase.query = newFrom + query.substring(first.length());
320-
}
321-
if (commands[0].toLowerCase(Locale.ROOT).startsWith("ts ")) {
322-
String[] parts = commands[0].split("\\s+");
323-
assert parts.length >= 2 : commands[0];
324-
String[] indices = parts[1].split(",");
325-
final boolean onlyRemotesFinal = onlyRemotes;
326-
parts[1] = Arrays.stream(indices)
327-
.map(index -> unquoteAndRequoteAsRemote(index.trim(), onlyRemotesFinal))
328-
.collect(Collectors.joining(","));
329-
String newNewMetrics = String.join(" ", parts);
330-
testCase.query = newNewMetrics + query.substring(first.length());
331329
}
330+
332331
int offset = testCase.query.length() - query.length();
333332
if (offset != 0) {
334333
final String pattern = "\\b1:(\\d+)\\b";

0 commit comments

Comments
 (0)