Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static String toString(Object value) {
if (value == null) {
return null;
}
if (value instanceof BytesRef) {
return ((BytesRef) value).utf8ToString();
if (value instanceof BytesRef bytesRef) {
return bytesRef.utf8ToString();
}
return value.toString();
}
Expand All @@ -36,8 +36,8 @@ public static BytesRef toBytesRef(Object value) {
if (value == null) {
return null;
}
if (value instanceof BytesRef) {
return (BytesRef) value;
if (value instanceof BytesRef bytesRef) {
return bytesRef;
}
return new BytesRef(value.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.esql.core.expression;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.xpack.esql.core.QlIllegalArgumentException;

public abstract class Foldables {
Expand All @@ -16,4 +17,11 @@ public static Object valueOf(FoldContext ctx, Expression e) {
}
throw new QlIllegalArgumentException("Cannot determine value for {}", e);
}

public static String stringLiteralValueOf(Expression expression, String message) {
if (expression instanceof Literal literal && literal.value() instanceof BytesRef bytesRef) {
return bytesRef.utf8ToString();
}
throw new QlIllegalArgumentException(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static org.elasticsearch.xpack.esql.core.expression.Foldables.stringLiteralValueOf;
import static org.elasticsearch.xpack.esql.session.EsqlCCSUtils.markClusterWithFinalStateAndNoShards;

/**
Expand Down Expand Up @@ -101,7 +102,9 @@ public EnrichPolicyResolver(
}

public record UnresolvedPolicy(String name, Enrich.Mode mode) {

public static UnresolvedPolicy from(Enrich e) {
return new UnresolvedPolicy(stringLiteralValueOf(e.policyName(), "Enrich policy must be a constant string"), e.mode());
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.action.support.SubscribableListener;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockUtils;
import org.elasticsearch.compute.data.Page;
Expand Down Expand Up @@ -46,7 +45,6 @@
import org.elasticsearch.xpack.esql.analysis.PreAnalyzer;
import org.elasticsearch.xpack.esql.analysis.Verifier;
import org.elasticsearch.xpack.esql.core.expression.Attribute;
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
import org.elasticsearch.xpack.esql.core.expression.ReferenceAttribute;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
Expand Down Expand Up @@ -88,6 +86,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

PreAnalyzer.PreAnalysis preAnalysis = preAnalyzer.preAnalyze(parsed);
var unresolvedPolicies = preAnalysis.enriches.stream()
.map(
e -> new EnrichPolicyResolver.UnresolvedPolicy(
BytesRefs.toString(e.policyName().fold(FoldContext.small() /* TODO remove me*/)),
e.mode()
)
)
.collect(Collectors.toSet());
var unresolvedPolicies = preAnalysis.enriches.stream().map(EnrichPolicyResolver.UnresolvedPolicy::from).collect(toSet());

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

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