Skip to content

Commit 7d5b692

Browse files
committed
Move flag to EsqlFlags
1 parent e1eaf49 commit 7d5b692

File tree

19 files changed

+741
-66
lines changed

19 files changed

+741
-66
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public class QueryPlanningBenchmark {
7474

7575
@Setup
7676
public void setup() {
77-
7877
this.config = new Configuration(
7978
DateUtils.UTC,
8079
Locale.US,
@@ -87,8 +86,7 @@ public void setup() {
8786
false,
8887
Map.of(),
8988
System.nanoTime(),
90-
false,
91-
true
89+
false
9290
);
9391

9492
var fields = 10_000;

benchmarks/src/main/java/org/elasticsearch/benchmark/compute/operator/EvalBenchmark.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ private static Configuration configuration() {
349349
false,
350350
Map.of(),
351351
0,
352-
false,
353-
true
352+
false
354353
);
355354
}
356355

patch.patch

Lines changed: 626 additions & 0 deletions
Large diffs are not rendered by default.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/regex/WildcardLike.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public Query asQuery(LucenePushdownPredicates pushdownPredicates, TranslatorHand
117117
LucenePushdownPredicates.checkIsPushableAttribute(field);
118118
return translateField(
119119
handler.nameOf(field instanceof FieldAttribute fa ? fa.exactAttribute() : field),
120-
pushdownPredicates.configuration().stringLikeOnIndex()
120+
pushdownPredicates.flags().stringLikeOnIndex()
121121
);
122122
}
123123

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LocalPhysicalOptimizerContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
package org.elasticsearch.xpack.esql.optimizer;
99

1010
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
11+
import org.elasticsearch.xpack.esql.plugin.EsqlFlags;
1112
import org.elasticsearch.xpack.esql.session.Configuration;
1213
import org.elasticsearch.xpack.esql.stats.SearchStats;
1314

14-
public record LocalPhysicalOptimizerContext(Configuration configuration, FoldContext foldCtx, SearchStats searchStats) {}
15+
public record LocalPhysicalOptimizerContext(EsqlFlags flags, Configuration configuration, FoldContext foldCtx, SearchStats searchStats) {}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public class EnableSpatialDistancePushdown extends PhysicalOptimizerRules.Parame
7777
protected PhysicalPlan rule(FilterExec filterExec, LocalPhysicalOptimizerContext ctx) {
7878
PhysicalPlan plan = filterExec;
7979
if (filterExec.child() instanceof EsQueryExec esQueryExec) {
80-
plan = rewrite(ctx.foldCtx(), filterExec, esQueryExec, LucenePushdownPredicates.from(ctx.searchStats(), ctx.configuration()));
80+
plan = rewrite(ctx.foldCtx(), filterExec, esQueryExec, LucenePushdownPredicates.from(ctx.searchStats(), ctx.flags()));
8181
} else if (filterExec.child() instanceof EvalExec evalExec && evalExec.child() instanceof EsQueryExec esQueryExec) {
8282
plan = rewriteBySplittingFilter(
8383
ctx.foldCtx(),
8484
filterExec,
8585
evalExec,
8686
esQueryExec,
87-
LucenePushdownPredicates.from(ctx.searchStats(), ctx.configuration())
87+
LucenePushdownPredicates.from(ctx.searchStats(), ctx.flags())
8888
);
8989
}
9090

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.elasticsearch.xpack.esql.core.expression.TypedAttribute;
1717
import org.elasticsearch.xpack.esql.core.type.DataType;
1818
import org.elasticsearch.xpack.esql.core.util.Check;
19-
import org.elasticsearch.xpack.esql.session.Configuration;
19+
import org.elasticsearch.xpack.esql.plugin.EsqlFlags;
2020
import org.elasticsearch.xpack.esql.stats.SearchStats;
2121

2222
/**
@@ -52,7 +52,7 @@ public interface LucenePushdownPredicates {
5252
@Nullable
5353
TransportVersion minTransportVersion();
5454

55-
Configuration configuration();
55+
EsqlFlags flags();
5656

5757
/**
5858
* For TEXT fields, we need to check if the field has a subfield of type KEYWORD that can be used instead.
@@ -125,21 +125,21 @@ static String pushableAttributeName(TypedAttribute attribute) {
125125
* In particular, it assumes TEXT fields have no exact subfields (underlying keyword field),
126126
* and that isAggregatable means indexed and has hasDocValues.
127127
*/
128-
LucenePushdownPredicates DEFAULT = forCanMatch(null, null);
128+
LucenePushdownPredicates DEFAULT = forCanMatch(null, new EsqlFlags(true));
129129

130130
/**
131131
* A {@link LucenePushdownPredicates} for use with the {@code can_match} phase.
132132
*/
133-
static LucenePushdownPredicates forCanMatch(TransportVersion minTransportVersion, Configuration configuration) {
133+
static LucenePushdownPredicates forCanMatch(TransportVersion minTransportVersion, EsqlFlags flags) {
134134
return new LucenePushdownPredicates() {
135135
@Override
136136
public TransportVersion minTransportVersion() {
137137
return minTransportVersion;
138138
}
139139

140140
@Override
141-
public Configuration configuration() {
142-
return configuration;
141+
public EsqlFlags flags() {
142+
return flags;
143143
}
144144

145145
@Override
@@ -170,7 +170,7 @@ public boolean canUseEqualityOnSyntheticSourceDelegate(FieldAttribute attr, Stri
170170
* If we have access to {@link SearchStats} over a collection of shards, we can make more fine-grained decisions about what can be
171171
* pushed down. This should open up more opportunities for lucene pushdown.
172172
*/
173-
static LucenePushdownPredicates from(SearchStats stats, Configuration configuration) {
173+
static LucenePushdownPredicates from(SearchStats stats, EsqlFlags flags) {
174174
// TODO: use FieldAttribute#fieldName, otherwise this doesn't apply to field attributes used for union types.
175175
// C.f. https://github.com/elastic/elasticsearch/issues/128905
176176
return new LucenePushdownPredicates() {
@@ -180,8 +180,8 @@ public TransportVersion minTransportVersion() {
180180
}
181181

182182
@Override
183-
public Configuration configuration() {
184-
return configuration;
183+
public EsqlFlags flags() {
184+
return flags;
185185
}
186186

187187
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected PhysicalPlan rule(FilterExec filterExec, LocalPhysicalOptimizerContext
5353
}
5454

5555
private static PhysicalPlan planFilterExec(FilterExec filterExec, EsQueryExec queryExec, LocalPhysicalOptimizerContext ctx) {
56-
LucenePushdownPredicates pushdownPredicates = LucenePushdownPredicates.from(ctx.searchStats(), ctx.configuration());
56+
LucenePushdownPredicates pushdownPredicates = LucenePushdownPredicates.from(ctx.searchStats(), ctx.flags());
5757
List<Expression> pushable = new ArrayList<>();
5858
List<Expression> nonPushable = new ArrayList<>();
5959
for (Expression exp : splitAnd(filterExec.condition())) {
@@ -75,7 +75,7 @@ private static PhysicalPlan planFilterExec(
7575
EsQueryExec queryExec,
7676
LocalPhysicalOptimizerContext ctx
7777
) {
78-
LucenePushdownPredicates pushdownPredicates = LucenePushdownPredicates.from(ctx.searchStats(), ctx.configuration());
78+
LucenePushdownPredicates pushdownPredicates = LucenePushdownPredicates.from(ctx.searchStats(), ctx.flags());
7979
AttributeMap<Attribute> aliasReplacedBy = getAliasReplacedBy(evalExec);
8080
List<Expression> pushable = new ArrayList<>();
8181
List<Expression> nonPushable = new ArrayList<>();

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ public class PushTopNToSource extends PhysicalOptimizerRules.ParameterizedOptimi
6363

6464
@Override
6565
protected PhysicalPlan rule(TopNExec topNExec, LocalPhysicalOptimizerContext ctx) {
66-
Pushable pushable = evaluatePushable(
67-
ctx.foldCtx(),
68-
topNExec,
69-
LucenePushdownPredicates.from(ctx.searchStats(), ctx.configuration())
70-
);
66+
Pushable pushable = evaluatePushable(ctx.foldCtx(), topNExec, LucenePushdownPredicates.from(ctx.searchStats(), ctx.flags()));
7167
return pushable.rewrite(topNExec);
7268
}
7369

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan;
5454
import org.elasticsearch.xpack.esql.planner.mapper.LocalMapper;
5555
import org.elasticsearch.xpack.esql.planner.mapper.Mapper;
56+
import org.elasticsearch.xpack.esql.plugin.EsqlFlags;
5657
import org.elasticsearch.xpack.esql.session.Configuration;
5758
import org.elasticsearch.xpack.esql.stats.SearchContextStats;
5859
import org.elasticsearch.xpack.esql.stats.SearchStats;
@@ -166,17 +167,26 @@ private static void forEachRelation(PhysicalPlan plan, Consumer<EsRelation> acti
166167
}
167168

168169
public static PhysicalPlan localPlan(
170+
EsqlFlags flags,
169171
List<SearchExecutionContext> searchContexts,
170172
Configuration configuration,
171173
FoldContext foldCtx,
172174
PhysicalPlan plan
173175
) {
174-
return localPlan(configuration, foldCtx, plan, SearchContextStats.from(searchContexts));
176+
return localPlan(flags, configuration, foldCtx, plan, SearchContextStats.from(searchContexts));
175177
}
176178

177-
public static PhysicalPlan localPlan(Configuration configuration, FoldContext foldCtx, PhysicalPlan plan, SearchStats searchStats) {
179+
public static PhysicalPlan localPlan(
180+
EsqlFlags flags,
181+
Configuration configuration,
182+
FoldContext foldCtx,
183+
PhysicalPlan plan,
184+
SearchStats searchStats
185+
) {
178186
final var logicalOptimizer = new LocalLogicalPlanOptimizer(new LocalLogicalOptimizerContext(configuration, foldCtx, searchStats));
179-
var physicalOptimizer = new LocalPhysicalPlanOptimizer(new LocalPhysicalOptimizerContext(configuration, foldCtx, searchStats));
187+
var physicalOptimizer = new LocalPhysicalPlanOptimizer(
188+
new LocalPhysicalOptimizerContext(flags, configuration, foldCtx, searchStats)
189+
);
180190

181191
return localPlan(plan, logicalOptimizer, physicalOptimizer);
182192
}
@@ -216,8 +226,13 @@ public static PhysicalPlan localPlan(
216226
/**
217227
* Extracts a filter that can be used to skip unmatched shards on the coordinator.
218228
*/
219-
public static QueryBuilder canMatchFilter(Configuration configuration, TransportVersion minTransportVersion, PhysicalPlan plan) {
220-
return detectFilter(configuration, minTransportVersion, plan, CoordinatorRewriteContext.SUPPORTED_FIELDS::contains);
229+
public static QueryBuilder canMatchFilter(
230+
EsqlFlags flags,
231+
Configuration configuration,
232+
TransportVersion minTransportVersion,
233+
PhysicalPlan plan
234+
) {
235+
return detectFilter(flags, configuration, minTransportVersion, plan, CoordinatorRewriteContext.SUPPORTED_FIELDS::contains);
221236
}
222237

223238
/**
@@ -226,14 +241,15 @@ public static QueryBuilder canMatchFilter(Configuration configuration, Transport
226241
* take care to not use it with TEXT fields.
227242
*/
228243
static QueryBuilder detectFilter(
244+
EsqlFlags flags,
229245
Configuration configuration,
230246
TransportVersion minTransportVersion,
231247
PhysicalPlan plan,
232248
Predicate<String> fieldName
233249
) {
234250
// first position is the REST filter, the second the query filter
235251
final List<QueryBuilder> requestFilters = new ArrayList<>();
236-
final LucenePushdownPredicates ctx = LucenePushdownPredicates.forCanMatch(minTransportVersion, configuration);
252+
final LucenePushdownPredicates ctx = LucenePushdownPredicates.forCanMatch(minTransportVersion, flags);
237253
plan.forEachDown(FragmentExec.class, fe -> {
238254
if (fe.esFilter() != null && fe.esFilter().supportsVersion(minTransportVersion)) {
239255
requestFilters.add(fe.esFilter());

0 commit comments

Comments
 (0)