Skip to content

Commit f4d969d

Browse files
authored
Store split indices (#138396)
1 parent 3aba4cd commit f4d969d

File tree

34 files changed

+289
-114
lines changed

34 files changed

+289
-114
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/_nightly/esql/QueryPlanningBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void setup() {
102102
mapping.put("field" + i, new EsField("field-" + i, TEXT, emptyMap(), true, EsField.TimeSeriesFieldType.NONE));
103103
}
104104

105-
var esIndex = new EsIndex("test", mapping, Map.of("test", IndexMode.STANDARD), Set.of());
105+
var esIndex = new EsIndex("test", mapping, Map.of("test", IndexMode.STANDARD), Map.of(), Map.of(), Set.of());
106106

107107
var functionRegistry = new EsqlFunctionRegistry();
108108

server/src/main/java/org/elasticsearch/transport/RemoteClusterAware.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,21 @@ public static List<String> getRemoteIndexExpressions(String... expressions) {
8888
*/
8989
public static String parseClusterAlias(String indexExpression) {
9090
assert indexExpression != null : "Must not pass null indexExpression";
91-
String[] parts = splitIndexName(indexExpression.trim());
92-
if (parts[0] == null) {
93-
return RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY;
94-
} else {
95-
return parts[0];
96-
}
91+
return getClusterAlias(splitIndexName(indexExpression.trim()));
92+
}
93+
94+
/**
95+
* @return the cluster alias or LOCAL_CLUSTER_GROUP_KEY if the split represents local index
96+
*/
97+
public static String getClusterAlias(String[] split) {
98+
return split[0] == null ? LOCAL_CLUSTER_GROUP_KEY : split[0];
99+
}
100+
101+
/**
102+
* @return the local index name from the qualified index name split by RemoteClusterAware#splitIndexName
103+
*/
104+
public static String getLocalIndexName(String[] split) {
105+
return split[1];
97106
}
98107

99108
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9226000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
keystore_details_in_reload_secure_settings_response,9225000
1+
esql_es_relation_add_split_indices,9226000

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/util/Holder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
package org.elasticsearch.xpack.esql.core.util;
99

10+
import java.util.function.Supplier;
11+
1012
/**
1113
* Simply utility class used for setting a state, typically
1214
* for closures (which require outside variables to be final).
@@ -36,7 +38,20 @@ public void setIfAbsent(T value) {
3638
}
3739
}
3840

41+
/**
42+
* Sets a value in the holder, but only if none has already been set.
43+
* @param value the new value to set.
44+
*/
45+
public void setOnce(T value) {
46+
assert this.value == null : "Value has already been set to " + this.value;
47+
this.value = value;
48+
}
49+
3950
public T get() {
4051
return value;
4152
}
53+
54+
public T getOrDefault(Supplier<T> defaultValue) {
55+
return value != null ? value : defaultValue.get();
56+
}
4257
}

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static EsRelation relation() {
324324
}
325325

326326
public static EsRelation relation(IndexMode mode) {
327-
return new EsRelation(EMPTY, randomIdentifier(), mode, Map.of(), List.of());
327+
return new EsRelation(EMPTY, randomIdentifier(), mode, Map.of(), Map.of(), Map.of(), List.of());
328328
}
329329

330330
/**

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/LookupFromIndexIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private PhysicalPlan buildGreaterThanFilter(long value) {
246246
new EsField("l", DataType.LONG, Collections.emptyMap(), true, EsField.TimeSeriesFieldType.NONE)
247247
);
248248
Expression greaterThan = new GreaterThan(Source.EMPTY, filterAttribute, new Literal(Source.EMPTY, value, DataType.LONG));
249-
EsRelation esRelation = new EsRelation(Source.EMPTY, "test", IndexMode.LOOKUP, Map.of(), List.of());
249+
EsRelation esRelation = new EsRelation(Source.EMPTY, "test", IndexMode.LOOKUP, Map.of(), Map.of(), Map.of(), List.of());
250250
Filter filter = new Filter(Source.EMPTY, esRelation, greaterThan);
251251
return new FragmentExec(filter);
252252
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/Analyzer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ private LogicalPlan resolveIndex(UnresolvedRelation plan, IndexResolution indexR
303303
plan.source(),
304304
esIndex.name(),
305305
plan.indexMode(),
306+
esIndex.originalIndices(),
307+
esIndex.concreteIndices(),
306308
esIndex.indexNameWithModes(),
307309
attributes.isEmpty() ? NO_FIELDS : attributes
308310
);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/EnrichPolicyResolver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,12 @@ public void messageReceived(LookupRequest request, TransportChannel channel, Tas
456456
false,
457457
false,
458458
refs.acquire(indexResult -> {
459-
if (indexResult.isValid() && indexResult.get().concreteIndices().size() == 1) {
459+
if (indexResult.isValid() && indexResult.get().concreteQualifiedIndices().size() == 1) {
460460
EsIndex esIndex = indexResult.get();
461-
var concreteIndices = Map.of(request.clusterAlias, Iterables.get(esIndex.concreteIndices(), 0));
461+
var concreteIndices = Map.of(
462+
request.clusterAlias,
463+
Iterables.get(esIndex.concreteQualifiedIndices(), 0)
464+
);
462465
var resolved = new ResolvedEnrichPolicy(
463466
p.getMatchField(),
464467
p.getType(),

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/QueryBuilderResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static QueryRewriteContext queryRewriteContext(TransportActionServices s
8585

8686
private static Set<String> indexNames(LogicalPlan plan) {
8787
Set<String> indexNames = new HashSet<>();
88-
plan.forEachDown(EsRelation.class, esRelation -> indexNames.addAll(esRelation.concreteIndices()));
88+
plan.forEachDown(EsRelation.class, esRelation -> indexNames.addAll(esRelation.concreteQualifiedIndices()));
8989
return indexNames;
9090
}
9191

0 commit comments

Comments
 (0)