Skip to content

Commit be9bd3a

Browse files
committed
Remove unnecessary fold in enrich policy name
1 parent 1bb9d2b commit be9bd3a

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.cluster.service.ClusterService;
1818
import org.elasticsearch.common.io.stream.StreamInput;
1919
import org.elasticsearch.common.io.stream.StreamOutput;
20+
import org.elasticsearch.common.lucene.BytesRefs;
2021
import org.elasticsearch.common.util.CollectionUtils;
2122
import org.elasticsearch.common.util.Maps;
2223
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
@@ -37,8 +38,11 @@
3738
import org.elasticsearch.xpack.core.ClientHelper;
3839
import org.elasticsearch.xpack.core.enrich.EnrichMetadata;
3940
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
41+
import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException;
4042
import org.elasticsearch.xpack.esql.action.EsqlExecutionInfo;
4143
import org.elasticsearch.xpack.esql.analysis.EnrichResolution;
44+
import org.elasticsearch.xpack.esql.core.expression.Expression;
45+
import org.elasticsearch.xpack.esql.core.expression.Literal;
4246
import org.elasticsearch.xpack.esql.core.type.DataType;
4347
import org.elasticsearch.xpack.esql.core.type.EsField;
4448
import org.elasticsearch.xpack.esql.core.util.StringUtils;
@@ -59,6 +63,7 @@
5963
import java.util.Set;
6064
import java.util.stream.Collectors;
6165

66+
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
6267
import static org.elasticsearch.xpack.esql.session.EsqlCCSUtils.markClusterWithFinalStateAndNoShards;
6368

6469
/**
@@ -101,7 +106,16 @@ public EnrichPolicyResolver(
101106
}
102107

103108
public record UnresolvedPolicy(String name, Enrich.Mode mode) {
109+
public static UnresolvedPolicy from(Enrich e) {
110+
return new UnresolvedPolicy(asString(e.policyName()), e.mode());
111+
}
104112

113+
private static String asString(Expression expression) {
114+
if (expression instanceof Literal literal) {
115+
return BytesRefs.toString(literal.value());
116+
}
117+
throw new EsqlIllegalArgumentException(format(null, "Enrich policy must be a constant string"));
118+
}
105119
}
106120

107121
/**

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.action.search.ShardSearchFailure;
1616
import org.elasticsearch.action.support.SubscribableListener;
1717
import org.elasticsearch.common.collect.Iterators;
18-
import org.elasticsearch.common.lucene.BytesRefs;
1918
import org.elasticsearch.compute.data.Block;
2019
import org.elasticsearch.compute.data.BlockUtils;
2120
import org.elasticsearch.compute.data.Page;
@@ -46,7 +45,6 @@
4645
import org.elasticsearch.xpack.esql.analysis.PreAnalyzer;
4746
import org.elasticsearch.xpack.esql.analysis.Verifier;
4847
import org.elasticsearch.xpack.esql.core.expression.Attribute;
49-
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
5048
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
5149
import org.elasticsearch.xpack.esql.core.tree.Source;
5250
import org.elasticsearch.xpack.esql.core.type.DataType;
@@ -88,6 +86,7 @@
8886
import java.util.stream.Collectors;
8987
import java.util.stream.Stream;
9088

89+
import static java.util.stream.Collectors.toSet;
9190
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
9291
import static org.elasticsearch.xpack.esql.core.tree.Source.EMPTY;
9392
import static org.elasticsearch.xpack.esql.plan.logical.join.InlineJoin.firstSubPlan;
@@ -382,14 +381,7 @@ public void analyzedPlan(
382381
};
383382

384383
PreAnalyzer.PreAnalysis preAnalysis = preAnalyzer.preAnalyze(parsed);
385-
var unresolvedPolicies = preAnalysis.enriches.stream()
386-
.map(
387-
e -> new EnrichPolicyResolver.UnresolvedPolicy(
388-
BytesRefs.toString(e.policyName().fold(FoldContext.small() /* TODO remove me*/)),
389-
e.mode()
390-
)
391-
)
392-
.collect(Collectors.toSet());
384+
var unresolvedPolicies = preAnalysis.enriches.stream().map(EnrichPolicyResolver.UnresolvedPolicy::from).collect(toSet());
393385

394386
EsqlCCSUtils.initCrossClusterState(indicesExpressionGrouper, verifier.licenseState(), preAnalysis.indices, executionInfo);
395387

@@ -592,7 +584,7 @@ private IndexResolution checkSingleIndex(
592584
) {
593585
// If all indices resolve to the same name, we can use that for BWC
594586
// Older clusters only can handle one name in LOOKUP JOIN
595-
var localIndexNames = indexNames.stream().map(n -> RemoteClusterAware.splitIndexName(n)[1]).collect(Collectors.toSet());
587+
var localIndexNames = indexNames.stream().map(n -> RemoteClusterAware.splitIndexName(n)[1]).collect(toSet());
596588
if (localIndexNames.size() == 1) {
597589
String indexName = localIndexNames.iterator().next();
598590
EsIndex newIndex = new EsIndex(index, lookupIndexResolution.get().mapping(), Map.of(indexName, IndexMode.LOOKUP));

0 commit comments

Comments
 (0)