|
@@ -32,12 +32,12 @@ import org.elasticsearch.xpack.esql.index.EsIndex;
|
|
|
import org.elasticsearch.xpack.esql.index.IndexResolution;
|
|
|
import org.elasticsearch.xpack.esql.plan.IndexPattern;
|
|
|
import org.elasticsearch.xpack.esql.type.EsFieldTests;
|
|
|
+import org.hamcrest.Matcher;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.EnumSet;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
@@ -60,20 +60,16 @@ public class EsqlCCSUtilsTests extends ESTestCase {
|
|
|
private final String REMOTE2_ALIAS = "remote2";
|
|
|
|
|
|
public void testCreateIndexExpressionFromAvailableClusters() {
|
|
|
-
|
|
|
+ var skipped = EsqlExecutionInfo.Cluster.Status.SKIPPED;
|
|
|
// no clusters marked as skipped
|
|
|
{
|
|
|
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
|
|
|
executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "logs*", false));
|
|
|
executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*", true));
|
|
|
executionInfo.swapCluster(REMOTE2_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true));
|
|
|
-
|
|
|
- String indexExpr = EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo);
|
|
|
- List<String> list = Arrays.stream(Strings.splitStringByCommaToArray(indexExpr)).toList();
|
|
|
- assertThat(list.size(), equalTo(5));
|
|
|
- assertThat(
|
|
|
- new HashSet<>(list),
|
|
|
- equalTo(Strings.commaDelimitedListToSet("logs*,remote1:*,remote2:mylogs1,remote2:mylogs2,remote2:logs*"))
|
|
|
+ assertIndexPattern(
|
|
|
+ EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo),
|
|
|
+ containsInAnyOrder("logs*", "remote1:*", "remote2:mylogs1", "remote2:mylogs2", "remote2:logs*")
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -84,38 +80,23 @@ public class EsqlCCSUtilsTests extends ESTestCase {
|
|
|
executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*,foo", true));
|
|
|
executionInfo.swapCluster(
|
|
|
REMOTE2_ALIAS,
|
|
|
- (k, v) -> new EsqlExecutionInfo.Cluster(
|
|
|
- REMOTE2_ALIAS,
|
|
|
- "mylogs1,mylogs2,logs*",
|
|
|
- true,
|
|
|
- EsqlExecutionInfo.Cluster.Status.SKIPPED
|
|
|
- )
|
|
|
+ (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true, skipped)
|
|
|
+ );
|
|
|
+ assertIndexPattern(
|
|
|
+ EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo),
|
|
|
+ containsInAnyOrder("logs*", "remote1:*", "remote1:foo")
|
|
|
);
|
|
|
-
|
|
|
- String indexExpr = EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo);
|
|
|
- List<String> list = Arrays.stream(Strings.splitStringByCommaToArray(indexExpr)).toList();
|
|
|
- assertThat(list.size(), equalTo(3));
|
|
|
- assertThat(new HashSet<>(list), equalTo(Strings.commaDelimitedListToSet("logs*,remote1:*,remote1:foo")));
|
|
|
}
|
|
|
|
|
|
// two clusters marked as skipped, so only local cluster present in revised index expression
|
|
|
{
|
|
|
EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
|
|
|
executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "logs*", false));
|
|
|
- executionInfo.swapCluster(
|
|
|
- REMOTE1_ALIAS,
|
|
|
- (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*,foo", true, EsqlExecutionInfo.Cluster.Status.SKIPPED)
|
|
|
- );
|
|
|
+ executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "*,foo", true, skipped));
|
|
|
executionInfo.swapCluster(
|
|
|
REMOTE2_ALIAS,
|
|
|
- (k, v) -> new EsqlExecutionInfo.Cluster(
|
|
|
- REMOTE2_ALIAS,
|
|
|
- "mylogs1,mylogs2,logs*",
|
|
|
- true,
|
|
|
- EsqlExecutionInfo.Cluster.Status.SKIPPED
|
|
|
- )
|
|
|
+ (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true, skipped)
|
|
|
);
|
|
|
-
|
|
|
assertThat(EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo), equalTo("logs*"));
|
|
|
}
|
|
|
|
|
@@ -128,18 +109,64 @@ public class EsqlCCSUtilsTests extends ESTestCase {
|
|
|
);
|
|
|
executionInfo.swapCluster(
|
|
|
REMOTE2_ALIAS,
|
|
|
- (k, v) -> new EsqlExecutionInfo.Cluster(
|
|
|
- REMOTE2_ALIAS,
|
|
|
- "mylogs1,mylogs2,logs*",
|
|
|
- true,
|
|
|
- EsqlExecutionInfo.Cluster.Status.SKIPPED
|
|
|
- )
|
|
|
+ (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "mylogs1,mylogs2,logs*", true, skipped)
|
|
|
);
|
|
|
-
|
|
|
assertThat(EsqlCCSUtils.createIndexExpressionFromAvailableClusters(executionInfo), equalTo(""));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testCreateQualifiedLookupIndexExpressionFromAvailableClusters() {
|
|
|
+
|
|
|
+ var skipped = EsqlExecutionInfo.Cluster.Status.SKIPPED;
|
|
|
+ // no clusters marked as skipped
|
|
|
+ {
|
|
|
+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
|
|
|
+ executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "", false));
|
|
|
+ executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "", true));
|
|
|
+ executionInfo.swapCluster(REMOTE2_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "", true));
|
|
|
+ assertIndexPattern(
|
|
|
+ EsqlCCSUtils.createQualifiedLookupIndexExpressionFromAvailableClusters(executionInfo, "lookup"),
|
|
|
+ containsInAnyOrder("lookup", REMOTE1_ALIAS + ":lookup", REMOTE2_ALIAS + ":lookup")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // one cluster marked as skipped
|
|
|
+ {
|
|
|
+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
|
|
|
+ executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "", false));
|
|
|
+ executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "", true));
|
|
|
+ executionInfo.swapCluster(REMOTE2_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "", true, skipped));
|
|
|
+ assertIndexPattern(
|
|
|
+ EsqlCCSUtils.createQualifiedLookupIndexExpressionFromAvailableClusters(executionInfo, "lookup"),
|
|
|
+ containsInAnyOrder("lookup", REMOTE1_ALIAS + ":lookup")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // all remotes marked as skipped
|
|
|
+ {
|
|
|
+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
|
|
|
+ executionInfo.swapCluster(LOCAL_CLUSTER_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(LOCAL_CLUSTER_ALIAS, "", false));
|
|
|
+ executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "", true, skipped));
|
|
|
+ executionInfo.swapCluster(REMOTE2_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "", true, skipped));
|
|
|
+ assertIndexPattern(
|
|
|
+ EsqlCCSUtils.createQualifiedLookupIndexExpressionFromAvailableClusters(executionInfo, "lookup"),
|
|
|
+ containsInAnyOrder("lookup")
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // all remotes are skipped and no local
|
|
|
+ {
|
|
|
+ EsqlExecutionInfo executionInfo = new EsqlExecutionInfo(true);
|
|
|
+ executionInfo.swapCluster(REMOTE1_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE1_ALIAS, "", true, skipped));
|
|
|
+ executionInfo.swapCluster(REMOTE2_ALIAS, (k, v) -> new EsqlExecutionInfo.Cluster(REMOTE2_ALIAS, "", true, skipped));
|
|
|
+ assertIndexPattern(
|
|
|
+ EsqlCCSUtils.createQualifiedLookupIndexExpressionFromAvailableClusters(executionInfo, "lookup"),
|
|
|
+ containsInAnyOrder()
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void assertIndexPattern(String indexPattern, Matcher<Iterable<? extends String>> matcher) {
|
|
|
+ assertThat(Set.of(Strings.splitStringByCommaToArray(indexPattern)), matcher);
|
|
|
+ }
|
|
|
+
|
|
|
public void testUpdateExecutionInfoWithUnavailableClusters() {
|
|
|
|
|
|
// skip_unavailable=true clusters are unavailable, both marked as SKIPPED
|
|
@@ -806,5 +833,4 @@ public class EsqlCCSUtilsTests extends ESTestCase {
|
|
|
return originalIndicesMap;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|