Skip to content

Revert "Add ES|QL version support with its default value (#791)" #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
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 @@ -22,7 +22,6 @@
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch.esql.ElasticsearchEsqlAsyncClient;
import co.elastic.clients.elasticsearch.esql.ElasticsearchEsqlClient;
import co.elastic.clients.elasticsearch.esql.EsqlVersion;
import co.elastic.clients.elasticsearch.esql.QueryRequest;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.transport.endpoints.BinaryResponse;
Expand All @@ -37,9 +36,9 @@ public class EsqlHelper {
//----- Synchronous

public static <T> T query(
ElasticsearchEsqlClient client, EsqlVersion version, EsqlAdapter<T> adapter, String query, Object... params
ElasticsearchEsqlClient client, EsqlAdapter<T> adapter, String query, Object... params
) throws IOException {
QueryRequest request = buildRequest(version, adapter, query, params);
QueryRequest request = buildRequest(adapter, query, params);
BinaryResponse response = client.query(request);
return adapter.deserialize(client, request, response);
}
Expand All @@ -53,9 +52,9 @@ public static <T> T query(ElasticsearchEsqlClient client, EsqlAdapter<T> adapter
//----- Asynchronous

public static <T> CompletableFuture<T> queryAsync(
ElasticsearchEsqlAsyncClient client, EsqlVersion version, EsqlAdapter<T> adapter, String query, Object... params
ElasticsearchEsqlAsyncClient client, EsqlAdapter<T> adapter, String query, Object... params
) {
return doQueryAsync(client, adapter, buildRequest(version, adapter, query, params));
return doQueryAsync(client, adapter, buildRequest(adapter, query, params));
}

public static <T> CompletableFuture<T> queryAsync(
Expand All @@ -80,19 +79,9 @@ private static <T> CompletableFuture<T> doQueryAsync(

//----- Utilities

private static QueryRequest buildRequest(EsqlVersion version, EsqlAdapter<?> adapter, String query, Object... params) {
if (version == null) {
version = EsqlVersion.getDefault();
}
if (version == null) {
throw new IllegalStateException(
"ES|QL default version not set. Either specify it explicitly or set a default value");
}
EsqlVersion v = version;

private static QueryRequest buildRequest(EsqlAdapter<?> adapter, String query, Object... params) {
return QueryRequest.of(esql -> esql
.format(adapter.format())
.version(v)
.columnar(adapter.columnar())
.query(query)
.params(asFieldValues(params))
Expand All @@ -110,7 +99,6 @@ private static QueryRequest buildRequest(EsqlAdapter<?> adapter, QueryRequest re
.locale(request.locale())
.params(request.params())
.query(request.query())
.version(request.version())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,7 @@ public final CompletableFuture<BinaryResponse> query(
* values for query parameters, if any
*/
public final <T> CompletableFuture<T> query(EsqlAdapter<T> adapter, String query, Object... parameters) {
return EsqlHelper.queryAsync(this, null, adapter, query, parameters);
}

/**
* Executes an ES|QL request and adapts its result to a target type.
*
* @param version
* the ES|QL language version
* @param adapter
* the ES|QL response adapter
* @param query
* the ES|QL query
* @param parameters
* values for query parameters, if any
*/
public final <T> CompletableFuture<T> query(EsqlVersion version, EsqlAdapter<T> adapter, String query,
Object... parameters) {
return EsqlHelper.queryAsync(this, version, adapter, query, parameters);
return EsqlHelper.queryAsync(this, adapter, query, parameters);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,7 @@ public final BinaryResponse query(Function<QueryRequest.Builder, ObjectBuilder<Q
*/
public final <T> T query(EsqlAdapter<T> adapter, String query, Object... parameters)
throws IOException, ElasticsearchException {
return EsqlHelper.query(this, null, adapter, query, parameters);
}

/**
* Executes an ES|QL request and adapts its result to a target type.
*
* @param version
* the ES|QL language version
* @param adapter
* the ES|QL response adapter
* @param query
* the ES|QL query
* @param parameters
* values for query parameters, if any
*/
public final <T> T query(EsqlVersion version, EsqlAdapter<T> adapter, String query, Object... parameters)
throws IOException, ElasticsearchException {
return EsqlHelper.query(this, version, adapter, query, parameters);
return EsqlHelper.query(this, adapter, query, parameters);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public class QueryRequest extends RequestBase implements JsonpSerializable {

private final String query;

private final EsqlVersion version;

// ---------------------------------------------------------------------------------------------

private QueryRequest(Builder builder) {
Expand All @@ -103,7 +101,6 @@ private QueryRequest(Builder builder) {
this.locale = builder.locale;
this.params = ApiTypeHelper.unmodifiable(builder.params);
this.query = ApiTypeHelper.requireNonNull(builder.query, this, "query");
this.version = ApiTypeHelper.requireNonNull(builder.version, this, "version");

}

Expand Down Expand Up @@ -185,16 +182,6 @@ public final String query() {
return this.query;
}

/**
* Required - The version of the ES|QL language in which the &quot;query&quot;
* field was written.
* <p>
* API name: {@code version}
*/
public final EsqlVersion version() {
return this.version;
}

/**
* Serialize this object to JSON.
*/
Expand Down Expand Up @@ -234,9 +221,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("query");
generator.write(this.query);

generator.writeKey("version");
this.version.serialize(generator, mapper);

}

// ---------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -266,8 +250,6 @@ public static class Builder extends RequestBase.AbstractBuilder<Builder> impleme

private String query;

private EsqlVersion version;

/**
* By default, ES|QL returns results as rows. For example, FROM returns each
* individual document as one row. For the JSON, YAML, CBOR and smile formats,
Expand Down Expand Up @@ -383,17 +365,6 @@ public final Builder query(String value) {
return this;
}

/**
* Required - The version of the ES|QL language in which the &quot;query&quot;
* field was written.
* <p>
* API name: {@code version}
*/
public final Builder version(EsqlVersion value) {
this.version = value;
return this;
}

@Override
protected Builder self() {
return this;
Expand All @@ -410,10 +381,6 @@ public QueryRequest build() {

return new QueryRequest(this);
}
{
// Use the default ES|QL language version if not set explicitly
this.version = EsqlVersion.getDefault();
}
}

// ---------------------------------------------------------------------------------------------
Expand All @@ -431,7 +398,6 @@ protected static void setupQueryRequestDeserializer(ObjectDeserializer<QueryRequ
op.add(Builder::locale, JsonpDeserializer.stringDeserializer(), "locale");
op.add(Builder::params, JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER), "params");
op.add(Builder::query, JsonpDeserializer.stringDeserializer(), "query");
op.add(Builder::version, EsqlVersion._DESERIALIZER, "version");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public synchronized ElasticsearchTestServer start() {
return this;
}

Version version = Version.VERSION.major() < 8 ? new Version(7,17,5,false) : new Version(8,14,0,false);
Version version = Version.VERSION.major() < 8 ? new Version(7,17,5,false) : new Version(8,12,0,false);

// Note we could use version.major() + "." + version.minor() + "-SNAPSHOT" but plugins won't install on a snapshot version
String esImage = "docker.elastic.co/elasticsearch/elasticsearch:" + version + "-SNAPSHOT";
String esImage = "docker.elastic.co/elasticsearch/elasticsearch:" + version;

DockerImageName image;
if (plugins.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void objectsTest() throws Exception {
{
EmpData emp = it.next();
assertEquals("10042", emp.empNo);
assertEquals(Arrays.asList("Architect", "Business Analyst", "Junior Developer", "Internship"), emp.jobPositions);
assertEquals(Arrays.asList("Architect", "Business Analyst", "Internship", "Junior Developer"), emp.jobPositions);

assertEquals("1993-03-21T00:00:00Z[UTC]",
DateTimeFormatter.ISO_DATE_TIME.format(emp.hireDate.toInstant().atZone(ZoneId.of("UTC")))
Expand Down Expand Up @@ -172,7 +172,7 @@ public void asyncObjects() throws Exception {
{
EmpData emp = it.next();
assertEquals("10042", emp.empNo);
assertEquals(Arrays.asList("Architect", "Business Analyst", "Junior Developer", "Internship"), emp.jobPositions);
assertEquals(Arrays.asList("Architect", "Business Analyst", "Internship", "Junior Developer"), emp.jobPositions);

assertEquals("1993-03-21T00:00:00Z[UTC]",
DateTimeFormatter.ISO_DATE_TIME.format(emp.hireDate.toInstant().atZone(ZoneId.of("UTC")))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public void i0254_suggesterTest() throws Exception {
}

@Test
@Disabled("Plugins cannot be installed on snapshot versions of ES")
public void i0249_variantKind() throws Exception {
try (ElasticsearchTestServer server = new ElasticsearchTestServer("analysis-icu").start()) {

Expand Down
Loading