Skip to content

Commit e41327b

Browse files
committed
Register the KQL function in various places.
1 parent 8295038 commit e41327b

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.xpack.esql.expression.function.aggregate.FilteredExpression;
3232
import org.elasticsearch.xpack.esql.expression.function.aggregate.Rate;
3333
import org.elasticsearch.xpack.esql.expression.function.fulltext.FullTextFunction;
34+
import org.elasticsearch.xpack.esql.expression.function.fulltext.Kql;
3435
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
3536
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryString;
3637
import org.elasticsearch.xpack.esql.expression.function.grouping.GroupingFunction;
@@ -684,6 +685,14 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Set<Failure> f
684685
qsf -> "[" + qsf.functionName() + "] " + qsf.functionType(),
685686
failures
686687
);
688+
checkCommandsBeforeExpression(
689+
plan,
690+
condition,
691+
Kql.class,
692+
lp -> (lp instanceof Filter || lp instanceof OrderBy || lp instanceof EsRelation),
693+
kqlFunc -> "[" + kqlFunc.functionName() + "] " + kqlFunc.functionType(),
694+
failures
695+
);
687696
checkCommandsBeforeExpression(
688697
plan,
689698
condition,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.elasticsearch.xpack.esql.expression.function.aggregate.Top;
3333
import org.elasticsearch.xpack.esql.expression.function.aggregate.Values;
3434
import org.elasticsearch.xpack.esql.expression.function.aggregate.WeightedAvg;
35+
import org.elasticsearch.xpack.esql.expression.function.fulltext.Kql;
3536
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
3637
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryString;
3738
import org.elasticsearch.xpack.esql.expression.function.grouping.Bucket;
@@ -406,7 +407,8 @@ private static FunctionDefinition[][] snapshotFunctions() {
406407
// This is an experimental function and can be removed without notice.
407408
def(Delay.class, Delay::new, "delay"),
408409
def(Categorize.class, Categorize::new, "categorize"),
409-
def(Rate.class, Rate::withUnresolvedTimestamp, "rate") } };
410+
def(Rate.class, Rate::withUnresolvedTimestamp, "rate"),
411+
def(Kql.class, Kql::new, "kql") } };
410412
}
411413

412414
public EsqlFunctionRegistry snapshotRegistry() {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
import org.apache.lucene.util.BytesRef;
1111
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
12+
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
1213
import org.elasticsearch.xpack.esql.core.expression.Expression;
1314
import org.elasticsearch.xpack.esql.core.expression.Nullability;
1415
import org.elasticsearch.xpack.esql.core.expression.TypeResolutions;
1516
import org.elasticsearch.xpack.esql.core.expression.function.Function;
1617
import org.elasticsearch.xpack.esql.core.tree.Source;
1718
import org.elasticsearch.xpack.esql.core.type.DataType;
1819

20+
import java.util.ArrayList;
21+
import java.util.Collections;
1922
import java.util.List;
2023

2124
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
@@ -30,7 +33,13 @@
3033
*/
3134
public abstract class FullTextFunction extends Function {
3235
public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
33-
return List.of(QueryString.ENTRY, Match.ENTRY);
36+
List<NamedWriteableRegistry.Entry> writeables = new ArrayList<>(List.of(QueryString.ENTRY, Match.ENTRY));
37+
38+
if (EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled()) {
39+
writeables.add(Kql.ENTRY);
40+
}
41+
42+
return Collections.unmodifiableList(writeables);
3443
}
3544

3645
private final Expression query;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/physical/local/PushFiltersToSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import org.elasticsearch.xpack.esql.core.type.DataType;
3232
import org.elasticsearch.xpack.esql.core.util.CollectionUtils;
3333
import org.elasticsearch.xpack.esql.core.util.Queries;
34+
import org.elasticsearch.xpack.esql.expression.function.fulltext.FullTextFunction;
3435
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
35-
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryString;
3636
import org.elasticsearch.xpack.esql.expression.function.scalar.ip.CIDRMatch;
3737
import org.elasticsearch.xpack.esql.expression.function.scalar.spatial.BinarySpatialFunction;
3838
import org.elasticsearch.xpack.esql.expression.function.scalar.spatial.SpatialRelatesFunction;
@@ -255,10 +255,10 @@ static boolean canPushToSource(Expression exp, LucenePushdownPredicates lucenePu
255255
return canPushSpatialFunctionToSource(spatial, lucenePushdownPredicates);
256256
} else if (exp instanceof StringQueryPredicate) {
257257
return true;
258-
} else if (exp instanceof QueryString) {
259-
return true;
260258
} else if (exp instanceof Match mf) {
261259
return mf.field() instanceof FieldAttribute && DataType.isString(mf.field().dataType());
260+
} else if (exp instanceof FullTextFunction) {
261+
return true;
262262
}
263263
return false;
264264
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/EsqlExpressionTranslators.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.xpack.esql.core.planner.ExpressionTranslator;
2424
import org.elasticsearch.xpack.esql.core.planner.ExpressionTranslators;
2525
import org.elasticsearch.xpack.esql.core.planner.TranslatorHandler;
26+
import org.elasticsearch.xpack.esql.core.querydsl.query.KqlQuery;
2627
import org.elasticsearch.xpack.esql.core.querydsl.query.MatchAll;
2728
import org.elasticsearch.xpack.esql.core.querydsl.query.MatchQuery;
2829
import org.elasticsearch.xpack.esql.core.querydsl.query.NotQuery;
@@ -34,6 +35,7 @@
3435
import org.elasticsearch.xpack.esql.core.tree.Source;
3536
import org.elasticsearch.xpack.esql.core.type.DataType;
3637
import org.elasticsearch.xpack.esql.core.util.Check;
38+
import org.elasticsearch.xpack.esql.expression.function.fulltext.Kql;
3739
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
3840
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryString;
3941
import org.elasticsearch.xpack.esql.expression.function.scalar.ip.CIDRMatch;
@@ -90,6 +92,7 @@ public final class EsqlExpressionTranslators {
9092
new ExpressionTranslators.MultiMatches(),
9193
new MatchFunctionTranslator(),
9294
new QueryStringFunctionTranslator(),
95+
new KqlFunctionTranslator(),
9396
new Scalars()
9497
);
9598

@@ -539,4 +542,11 @@ protected Query asQuery(QueryString queryString, TranslatorHandler handler) {
539542
return new QueryStringQuery(queryString.source(), queryString.queryAsText(), Map.of(), null);
540543
}
541544
}
545+
546+
public static class KqlFunctionTranslator extends ExpressionTranslator<Kql> {
547+
@Override
548+
protected Query asQuery(Kql kqlFunction, TranslatorHandler handler) {
549+
return new KqlQuery(kqlFunction.source(), kqlFunction.queryAsText());
550+
}
551+
}
542552
}

0 commit comments

Comments
 (0)