Skip to content

Commit 521da24

Browse files
Revert "Remove AutomatonQueryBuilder and EsqlAutomatonQuery"
This reverts commit 7484410.
1 parent 817336d commit 521da24

File tree

3 files changed

+159
-1
lines changed

3 files changed

+159
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.index.query;
11+
12+
import org.apache.lucene.index.Term;
13+
import org.apache.lucene.search.AutomatonQuery;
14+
import org.apache.lucene.search.Query;
15+
import org.apache.lucene.util.automaton.Automaton;
16+
import org.elasticsearch.TransportVersion;
17+
import org.elasticsearch.common.Strings;
18+
import org.elasticsearch.common.io.stream.StreamOutput;
19+
import org.elasticsearch.xcontent.XContentBuilder;
20+
21+
import java.io.IOException;
22+
import java.io.UnsupportedEncodingException;
23+
import java.util.Objects;
24+
25+
/**
26+
* Implements an Automaton query, which matches documents based on a Lucene Automaton.
27+
* It does not support serialization or XContent representation.
28+
*/
29+
public class AutomatonQueryBuilder extends AbstractQueryBuilder<AutomatonQueryBuilder> implements MultiTermQueryBuilder {
30+
private final String fieldName;
31+
private final Automaton automaton;
32+
private final String description;
33+
34+
public AutomatonQueryBuilder(String fieldName, Automaton automaton, String description) {
35+
if (Strings.isEmpty(fieldName)) {
36+
throw new IllegalArgumentException("field name is null or empty");
37+
}
38+
if (automaton == null) {
39+
throw new IllegalArgumentException("automaton cannot be null");
40+
}
41+
this.fieldName = fieldName;
42+
this.automaton = automaton;
43+
this.description = description;
44+
}
45+
46+
@Override
47+
public String fieldName() {
48+
return fieldName;
49+
}
50+
51+
@Override
52+
public String getWriteableName() {
53+
throw new UnsupportedOperationException("AutomatonQueryBuilder does not support getWriteableName");
54+
}
55+
56+
@Override
57+
public String getName() {
58+
return "AutomatonQueryBuilder";
59+
}
60+
61+
@Override
62+
protected void doWriteTo(StreamOutput out) throws IOException {
63+
throw new UnsupportedEncodingException("AutomatonQueryBuilder does not support doWriteTo");
64+
}
65+
66+
@Override
67+
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
68+
throw new UnsupportedEncodingException("AutomatonQueryBuilder does not support doXContent");
69+
}
70+
71+
@Override
72+
protected Query doToQuery(SearchExecutionContext context) throws IOException {
73+
return new AutomatonQueryWithDescription(new Term(fieldName), automaton, description);
74+
}
75+
76+
@Override
77+
protected int doHashCode() {
78+
return Objects.hash(fieldName, automaton, description);
79+
}
80+
81+
@Override
82+
protected boolean doEquals(AutomatonQueryBuilder other) {
83+
return Objects.equals(fieldName, other.fieldName)
84+
&& Objects.equals(automaton, other.automaton)
85+
&& Objects.equals(description, other.description);
86+
}
87+
88+
@Override
89+
public TransportVersion getMinimalSupportedVersion() {
90+
throw new UnsupportedOperationException("AutomatonQueryBuilder does not support getMinimalSupportedVersion");
91+
}
92+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
package org.elasticsearch.xpack.esql.core.querydsl.query;
8+
9+
import org.apache.lucene.util.automaton.Automaton;
10+
import org.elasticsearch.index.query.AutomatonQueryBuilder;
11+
import org.elasticsearch.index.query.QueryBuilder;
12+
import org.elasticsearch.xpack.esql.core.tree.Source;
13+
14+
import java.util.Objects;
15+
16+
/**
17+
* Query that matches documents based on a Lucene Automaton.
18+
*/
19+
public class EsqlAutomatonQuery extends Query {
20+
21+
private final String field;
22+
private final Automaton automaton;
23+
private final String automatonDescription;
24+
25+
public EsqlAutomatonQuery(Source source, String field, Automaton automaton, String automatonDescription) {
26+
super(source);
27+
this.field = field;
28+
this.automaton = automaton;
29+
this.automatonDescription = automatonDescription;
30+
}
31+
32+
public String field() {
33+
return field;
34+
}
35+
36+
@Override
37+
protected QueryBuilder asBuilder() {
38+
return new AutomatonQueryBuilder(field, automaton, automatonDescription);
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
return Objects.hash(field, automaton, automatonDescription);
44+
}
45+
46+
@Override
47+
public boolean equals(Object obj) {
48+
if (this == obj) {
49+
return true;
50+
}
51+
52+
if (obj == null || getClass() != obj.getClass()) {
53+
return false;
54+
}
55+
56+
EsqlAutomatonQuery other = (EsqlAutomatonQuery) obj;
57+
return Objects.equals(field, other.field)
58+
&& Objects.equals(automaton, other.automaton)
59+
&& Objects.equals(automatonDescription, other.automatonDescription);
60+
}
61+
62+
@Override
63+
protected String innerToString() {
64+
return "AutomatonQuery{" + "field='" + field + '\'' + '}';
65+
}
66+
}

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClustersIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private void assertClusterDetailsMap(Map<String, Object> result, boolean remoteO
289289
assertThat(remoteClusterShards.keySet(), equalTo(Set.of("total", "successful", "skipped", "failed")));
290290
assertThat((Integer) remoteClusterShards.get("total"), greaterThanOrEqualTo(0));
291291
assertThat((Integer) remoteClusterShards.get("successful"), equalTo((Integer) remoteClusterShards.get("total")));
292-
// assertThat((Integer) remoteClusterShards.get("skipped"), equalTo(0));
292+
assertThat((Integer) remoteClusterShards.get("skipped"), equalTo(0));
293293
assertThat((Integer) remoteClusterShards.get("failed"), equalTo(0));
294294

295295
if (remoteOnly == false) {

0 commit comments

Comments
 (0)