Skip to content

Commit a8d5b44

Browse files
Clean up
1 parent 77c541d commit a8d5b44

File tree

7 files changed

+33
-49
lines changed

7 files changed

+33
-49
lines changed

server/src/main/java/org/elasticsearch/index/query/WildcardLikeQueryBuilder.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.TransportVersion;
1717
import org.elasticsearch.TransportVersions;
1818
import org.elasticsearch.common.Strings;
19+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1920
import org.elasticsearch.common.io.stream.StreamInput;
2021
import org.elasticsearch.common.io.stream.StreamOutput;
2122
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
@@ -39,10 +40,13 @@
3940
* {@code ?}.
4041
*/
4142
public class WildcardLikeQueryBuilder extends AbstractQueryBuilder<WildcardLikeQueryBuilder> implements MultiTermQueryBuilder {
42-
public static final String NAME = "wildcardlike";
43+
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
44+
QueryBuilder.class,
45+
"wildcardLikeQueryBuilder",
46+
WildcardLikeQueryBuilder::new
47+
);
4348

4449
private static final ParseField WILDCARD_FIELD = new ParseField("wildcard");
45-
private static final ParseField VALUE_FIELD = new ParseField("value");
4650
private static final ParseField REWRITE_FIELD = new ParseField("rewrite");
4751

4852
private final String fieldName;
@@ -125,12 +129,12 @@ public boolean caseInsensitive() {
125129

126130
@Override
127131
public String getWriteableName() {
128-
return NAME;
132+
return ENTRY.name;
129133
}
130134

131135
@Override
132136
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
133-
builder.startObject(NAME);
137+
builder.startObject(ENTRY.name);
134138
builder.startObject(fieldName);
135139
builder.field(WILDCARD_FIELD.getPreferredName(), value);
136140
if (rewrite != null) {

server/src/main/java/org/elasticsearch/search/SearchModule.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.elasticsearch.index.query.TermQueryBuilder;
6767
import org.elasticsearch.index.query.TermsQueryBuilder;
6868
import org.elasticsearch.index.query.TermsSetQueryBuilder;
69-
import org.elasticsearch.index.query.WildcardLikeQueryBuilder;
7069
import org.elasticsearch.index.query.WildcardQueryBuilder;
7170
import org.elasticsearch.index.query.WrapperQueryBuilder;
7271
import org.elasticsearch.index.query.functionscore.ExponentialDecayFunctionBuilder;
@@ -1118,9 +1117,6 @@ private void registerQueryParsers(List<SearchPlugin> plugins) {
11181117
registerQuery(new QuerySpec<>(RangeQueryBuilder.NAME, RangeQueryBuilder::new, RangeQueryBuilder::fromXContent));
11191118
registerQuery(new QuerySpec<>(PrefixQueryBuilder.NAME, PrefixQueryBuilder::new, PrefixQueryBuilder::fromXContent));
11201119
registerQuery(new QuerySpec<>(WildcardQueryBuilder.NAME, WildcardQueryBuilder::new, WildcardQueryBuilder::fromXContent));
1121-
registerQuery(
1122-
new QuerySpec<>(WildcardLikeQueryBuilder.NAME, WildcardLikeQueryBuilder::new, WildcardLikeQueryBuilder::fromXContent)
1123-
);
11241120
registerQuery(
11251121
new QuerySpec<>(ConstantScoreQueryBuilder.NAME, ConstantScoreQueryBuilder::new, ConstantScoreQueryBuilder::fromXContent)
11261122
);

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
package org.elasticsearch.xpack.esql.expression.function.scalar.string.regex;
99

1010
import org.apache.lucene.util.automaton.Automaton;
11-
import org.elasticsearch.common.breaker.CircuitBreaker;
12-
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
1311
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1412
import org.elasticsearch.common.io.stream.StreamInput;
1513
import org.elasticsearch.common.io.stream.StreamOutput;
16-
import org.elasticsearch.common.util.BigArrays;
17-
import org.elasticsearch.compute.data.BlockFactory;
18-
import org.elasticsearch.compute.data.BlockStreamInput;
1914
import org.elasticsearch.xpack.esql.core.expression.Expression;
2015
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
2116
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.WildcardPattern;
@@ -71,11 +66,8 @@ public WildcardLikeList(StreamInput in) throws IOException {
7166
in.readNamedWriteable(Expression.class),
7267
new WildcardPatternList(in),
7368
deserializeCaseInsensitivity(in),
74-
null
69+
Configuration.readFrom(in)
7570
);
76-
BlockFactory blockFactory = new BlockFactory(new NoopCircuitBreaker(CircuitBreaker.REQUEST), BigArrays.NON_RECYCLING_INSTANCE);
77-
BlockStreamInput blockStreamInput = new BlockStreamInput(in, blockFactory);
78-
this.configuration = new Configuration(blockStreamInput);
7971
}
8072

8173
@Override

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/ExpressionQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Objects;
1616

1717
/**
18-
* Query that matches documents based on a Lucene Automaton.
18+
* Implements an Expression query, which matches documents based on a given expression.
1919
*/
2020
public class ExpressionQuery extends Query {
2121

@@ -60,6 +60,6 @@ public boolean equals(Object obj) {
6060

6161
@Override
6262
protected String innerToString() {
63-
return "AutomatonQuery{" + "field='" + targetFieldName + '\'' + '}';
63+
return "ExpressionQuery{" + "field='" + targetFieldName + '\'' + '}';
6464
}
6565
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/io/stream/ExpressionQueryBuilder.java

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,14 @@
77

88
package org.elasticsearch.xpack.esql.io.stream;
99

10-
import org.apache.lucene.index.Term;
11-
import org.apache.lucene.search.AutomatonQuery;
1210
import org.apache.lucene.search.MatchNoDocsQuery;
1311
import org.apache.lucene.search.Query;
1412
import org.apache.lucene.util.automaton.Automaton;
1513
import org.elasticsearch.TransportVersion;
1614
import org.elasticsearch.common.Strings;
17-
import org.elasticsearch.common.breaker.CircuitBreaker;
18-
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
1915
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
2016
import org.elasticsearch.common.io.stream.StreamInput;
2117
import org.elasticsearch.common.io.stream.StreamOutput;
22-
import org.elasticsearch.common.util.BigArrays;
23-
import org.elasticsearch.compute.data.BlockFactory;
24-
import org.elasticsearch.compute.data.BlockStreamInput;
2518
import org.elasticsearch.index.mapper.MappedFieldType;
2619
import org.elasticsearch.index.query.AbstractQueryBuilder;
2720
import org.elasticsearch.index.query.MultiTermQueryBuilder;
@@ -39,8 +32,10 @@
3932
import static org.apache.lucene.search.MultiTermQuery.CONSTANT_SCORE_REWRITE;
4033

4134
/**
42-
* Implements an Automaton query, which matches documents based on a Lucene Automaton.
43-
* It does not support serialization or XContent representation.
35+
* Implements an Expression query builder, which matches documents based on a given expression.
36+
* The expression itself must provide the asLuceneQuery and getLuceneQueryDescription methods
37+
* It allows for serialization of the expression and generate an AutomatonQuery on the data node
38+
* as Automaton does not support serialization.
4439
*/
4540
public class ExpressionQueryBuilder extends AbstractQueryBuilder<ExpressionQueryBuilder> implements MultiTermQueryBuilder {
4641
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
@@ -70,10 +65,8 @@ public ExpressionQueryBuilder(String fieldName, Expression expression, Configura
7065
public ExpressionQueryBuilder(StreamInput in) throws IOException {
7166
super(in);
7267
fieldName = in.readString();
73-
BlockFactory blockFactory = new BlockFactory(new NoopCircuitBreaker(CircuitBreaker.REQUEST), BigArrays.NON_RECYCLING_INSTANCE);
74-
BlockStreamInput blockStreamInput = new BlockStreamInput(in, blockFactory);
75-
this.config = new Configuration(blockStreamInput);
76-
PlanStreamInput planStreamInput = new PlanStreamInput(blockStreamInput, in.namedWriteableRegistry(), config);
68+
this.config = Configuration.readFrom(in);
69+
PlanStreamInput planStreamInput = new PlanStreamInput(in, in.namedWriteableRegistry(), config);
7770
this.expression = planStreamInput.readNamedWriteable(Expression.class);
7871
}
7972

@@ -129,21 +122,4 @@ protected boolean doEquals(ExpressionQueryBuilder other) {
129122
public TransportVersion getMinimalSupportedVersion() {
130123
throw new UnsupportedOperationException("AutomatonQueryBuilder does not support getMinimalSupportedVersion");
131124
}
132-
133-
static class AutomatonQueryWithDescription extends AutomatonQuery {
134-
private final String description;
135-
136-
AutomatonQueryWithDescription(Term term, Automaton automaton, String description) {
137-
super(term, automaton);
138-
this.description = description;
139-
}
140-
141-
@Override
142-
public String toString(String field) {
143-
if (this.field.equals(field)) {
144-
return description;
145-
}
146-
return this.field + ":" + description;
147-
}
148-
}
149125
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.compute.operator.topn.TopNOperatorStatus;
4040
import org.elasticsearch.core.TimeValue;
4141
import org.elasticsearch.features.NodeFeature;
42+
import org.elasticsearch.index.query.WildcardLikeQueryBuilder;
4243
import org.elasticsearch.license.XPackLicenseState;
4344
import org.elasticsearch.plugins.ActionPlugin;
4445
import org.elasticsearch.plugins.ExtensiblePlugin;
@@ -321,6 +322,7 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
321322
entries.add(EnrichLookupOperator.Status.ENTRY);
322323
entries.add(LookupFromIndexOperator.Status.ENTRY);
323324
entries.add(ExpressionQueryBuilder.ENTRY);
325+
entries.add(WildcardLikeQueryBuilder.ENTRY);
324326

325327
entries.addAll(ExpressionWritables.getNamedWriteables());
326328
entries.addAll(PlanWritables.getNamedWriteables());

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
package org.elasticsearch.xpack.esql.session;
99

1010
import org.elasticsearch.TransportVersions;
11+
import org.elasticsearch.common.breaker.CircuitBreaker;
12+
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
1113
import org.elasticsearch.common.bytes.BytesArray;
1214
import org.elasticsearch.common.compress.CompressorFactory;
1315
import org.elasticsearch.common.io.stream.StreamInput;
1416
import org.elasticsearch.common.io.stream.StreamOutput;
1517
import org.elasticsearch.common.io.stream.Writeable;
18+
import org.elasticsearch.common.util.BigArrays;
19+
import org.elasticsearch.compute.data.BlockFactory;
1620
import org.elasticsearch.compute.data.BlockStreamInput;
1721
import org.elasticsearch.xpack.esql.Column;
1822
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
@@ -309,4 +313,14 @@ public String toString() {
309313
+ '}';
310314
}
311315

316+
/**
317+
* This method is not very efficient because it creates a new BlockStreamInput
318+
* Please use the constructor that takes a BlockStreamInput instead if you already have a BlockStreamInput
319+
*/
320+
public static Configuration readFrom(StreamInput in) throws IOException {
321+
BlockFactory blockFactory = new BlockFactory(new NoopCircuitBreaker(CircuitBreaker.REQUEST), BigArrays.NON_RECYCLING_INSTANCE);
322+
BlockStreamInput blockStreamInput = new BlockStreamInput(in, blockFactory);
323+
return new Configuration(blockStreamInput);
324+
}
325+
312326
}

0 commit comments

Comments
 (0)