Skip to content
Closed
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 @@ -205,7 +205,7 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
checkCommandsBeforeExpression(
plan,
condition,
Match.class,
AbstractMatchFullTextFunction.class,
lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
m -> "[" + m.functionName() + "] " + m.functionType(),
failures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

package org.elasticsearch.xpack.esql.expression.function.fulltext;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.NodeInfo;
import org.elasticsearch.xpack.esql.core.tree.Source;
Expand All @@ -23,7 +26,7 @@
/**
* This class performs a {@link org.elasticsearch.xpack.esql.querydsl.query.MatchQuery} using an operator.
*/
public class MatchOperator extends Match {
public class MatchOperator extends AbstractMatchFullTextFunction {

public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
Expression.class,
Expand Down Expand Up @@ -60,15 +63,11 @@ public MatchOperator(
description = "Value to find in the provided field."
) Expression matchQuery
) {
super(source, field, matchQuery);
this(source, field, matchQuery, null);
}

private static Match readFrom(StreamInput in) throws IOException {
Source source = Source.readFrom((PlanStreamInput) in);
Expression field = in.readNamedWriteable(Expression.class);
Expression query = in.readNamedWriteable(Expression.class);

return new MatchOperator(source, field, query);
private MatchOperator(Source source, Expression field, Expression matchQuery, QueryBuilder queryBuilder) {
super(source, matchQuery, List.of(field, matchQuery), queryBuilder, field);
}

@Override
Expand All @@ -86,6 +85,27 @@ public String getWriteableName() {
return ENTRY.name;
}

private static MatchOperator readFrom(StreamInput in) throws IOException {
Source source = Source.readFrom((PlanStreamInput) in);
Expression field = in.readNamedWriteable(Expression.class);
Expression query = in.readNamedWriteable(Expression.class);
QueryBuilder queryBuilder = null;
if (in.getTransportVersion().onOrAfter(TransportVersions.ESQL_QUERY_BUILDER_IN_SEARCH_FUNCTIONS)) {
queryBuilder = in.readOptionalNamedWriteable(QueryBuilder.class);
}
return new MatchOperator(source, field, query, queryBuilder);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
source().writeTo(out);
out.writeNamedWriteable(field());
out.writeNamedWriteable(query());
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_QUERY_BUILDER_IN_SEARCH_FUNCTIONS)) {
out.writeOptionalNamedWriteable(queryBuilder());
}
}

@Override
protected NodeInfo<? extends Expression> info() {
return NodeInfo.create(this, MatchOperator::new, field(), query());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.elasticsearch.xpack.esql.expression.function.aggregate.Count;
import org.elasticsearch.xpack.esql.expression.function.aggregate.Max;
import org.elasticsearch.xpack.esql.expression.function.aggregate.Min;
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
import org.elasticsearch.xpack.esql.expression.function.fulltext.MatchOperator;
import org.elasticsearch.xpack.esql.expression.function.scalar.map.LogWithBaseInMap;
import org.elasticsearch.xpack.esql.index.EsIndex;
import org.elasticsearch.xpack.esql.index.IndexResolution;
Expand Down Expand Up @@ -2584,7 +2584,7 @@ public void testFromEnrichAndMatchColonUsage() {
""", "mapping-default.json");
var limit = as(plan, Limit.class);
var filter = as(limit.child(), Filter.class);
var match = as(filter.condition(), Match.class);
var match = as(filter.condition(), MatchOperator.class);
var enrich = as(filter.child(), Enrich.class);
assertEquals(enrich.mode(), Enrich.Mode.ANY);
assertEquals(enrich.policy().getMatchField(), "language_code");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.elasticsearch.xpack.esql.expression.UnresolvedNamePattern;
import org.elasticsearch.xpack.esql.expression.function.UnresolvedFunction;
import org.elasticsearch.xpack.esql.expression.function.aggregate.FilteredExpression;
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
import org.elasticsearch.xpack.esql.expression.function.fulltext.MatchOperator;
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.ToInteger;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
import org.elasticsearch.xpack.esql.expression.function.scalar.string.WildcardLike;
Expand Down Expand Up @@ -2316,7 +2316,7 @@ public void testMetricWithGroupKeyAsAgg() {
public void testMatchOperatorConstantQueryString() {
var plan = statement("FROM test | WHERE field:\"value\"");
var filter = as(plan, Filter.class);
var match = (Match) filter.condition();
var match = (MatchOperator) filter.condition();
var matchField = (UnresolvedAttribute) match.field();
assertThat(matchField.name(), equalTo("field"));
assertThat(match.query().fold(FoldContext.small()), equalTo("value"));
Expand Down Expand Up @@ -2360,7 +2360,7 @@ public void testMatchFunctionFieldCasting() {
public void testMatchOperatorFieldCasting() {
var plan = statement("FROM test | WHERE field::int : \"value\"");
var filter = as(plan, Filter.class);
var match = (Match) filter.condition();
var match = (MatchOperator) filter.condition();
var toInteger = (ToInteger) match.field();
var matchField = (UnresolvedAttribute) toInteger.field();
assertThat(matchField.name(), equalTo("field"));
Expand Down