Skip to content

Commit

Permalink
[codegen] update to latest spec (+ fixed esql adapter)
Browse files Browse the repository at this point in the history
  • Loading branch information
l-trotta committed Sep 16, 2024
1 parent 27f87e6 commit e2912c3
Show file tree
Hide file tree
Showing 17 changed files with 2,276 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import co.elastic.clients.elasticsearch.esql.ElasticsearchEsqlAsyncClient;
import co.elastic.clients.elasticsearch.esql.ElasticsearchEsqlClient;
import co.elastic.clients.elasticsearch.esql.QueryRequest;
import co.elastic.clients.elasticsearch.esql.query.EsqlFormat;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.transport.endpoints.BinaryResponse;

Expand Down Expand Up @@ -81,7 +82,7 @@ private static <T> CompletableFuture<T> doQueryAsync(

private static QueryRequest buildRequest(EsqlAdapter<?> adapter, String query, Object... params) {
return QueryRequest.of(esql -> esql
.format(adapter.format())
.format(EsqlFormat._DESERIALIZER.parse(adapter.format()))
.columnar(adapter.columnar())
.query(query)
.params(asFieldValues(params))
Expand All @@ -91,7 +92,7 @@ private static QueryRequest buildRequest(EsqlAdapter<?> adapter, String query, O
private static QueryRequest buildRequest(EsqlAdapter<?> adapter, QueryRequest request) {
return QueryRequest.of(q -> q
// Set/override format and columnar
.format(adapter.format())
.format(EsqlFormat._DESERIALIZER.parse(adapter.format()))
.columnar(adapter.columnar())

.delimiter(request.delimiter())
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch.esql.query.EsqlFormat;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class QueryRequest extends RequestBase implements JsonpSerializable {
private final Query filter;

@Nullable
private final String format;
private final EsqlFormat format;

@Nullable
private final String locale;
Expand Down Expand Up @@ -149,7 +150,7 @@ public final Query filter() {
* API name: {@code format}
*/
@Nullable
public final String format() {
public final EsqlFormat format() {
return this.format;
}

Expand Down Expand Up @@ -240,7 +241,7 @@ public static class Builder extends RequestBase.AbstractBuilder<Builder> impleme
private Query filter;

@Nullable
private String format;
private EsqlFormat format;

@Nullable
private String locale;
Expand Down Expand Up @@ -300,7 +301,7 @@ public final Builder filter(Function<Query.Builder, ObjectBuilder<Query>> fn) {
* <p>
* API name: {@code format}
*/
public final Builder format(@Nullable String value) {
public final Builder format(@Nullable EsqlFormat value) {
this.format = value;
return this;
}
Expand Down Expand Up @@ -433,7 +434,7 @@ protected static void setupQueryRequestDeserializer(ObjectDeserializer<QueryRequ
params.put("delimiter", request.delimiter);
}
if (request.format != null) {
params.put("format", request.format);
params.put("format", request.format.jsonValue());
}
return params;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package co.elastic.clients.elasticsearch.esql.query;

import co.elastic.clients.json.JsonEnum;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;

//----------------------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------------------
//
// This code is generated from the Elasticsearch API specification
// at https://github.com/elastic/elasticsearch-specification
//
// Manual updates to this file will be lost when the code is
// re-generated.
//
// If you find a property that is missing or wrongly typed, please
// open an issue or a PR on the API specification repository.
//
//----------------------------------------------------------------

/**
*
* @see <a href="../../doc-files/api-spec.html#esql.query.EsqlFormat">API
* specification</a>
*/
@JsonpDeserializable
public enum EsqlFormat implements JsonEnum {
Csv("csv"),

Json("json"),

Tsv("tsv"),

Txt("txt"),

Yaml("yaml"),

Cbor("cbor"),

Smile("smile"),

Arrow("arrow"),

;

private final String jsonValue;

EsqlFormat(String jsonValue) {
this.jsonValue = jsonValue;
}

public String jsonValue() {
return this.jsonValue;
}

public static final JsonEnum.Deserializer<EsqlFormat> _DESERIALIZER = new JsonEnum.Deserializer<>(
EsqlFormat.values());
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public enum Kind implements JsonEnum {

Pipeline("pipeline"),

Redact("redact"),

Remove("remove"),

Rename("rename"),
Expand Down Expand Up @@ -626,6 +628,23 @@ public PipelineProcessor pipeline() {
return TaggedUnionUtils.get(this, Kind.Pipeline);
}

/**
* Is this variant instance of kind {@code redact}?
*/
public boolean isRedact() {
return _kind == Kind.Redact;
}

/**
* Get the {@code redact} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code redact} kind.
*/
public RedactProcessor redact() {
return TaggedUnionUtils.get(this, Kind.Redact);
}

/**
* Is this variant instance of kind {@code remove}?
*/
Expand Down Expand Up @@ -1167,6 +1186,16 @@ public ObjectBuilder<Processor> pipeline(
return this.pipeline(fn.apply(new PipelineProcessor.Builder()).build());
}

public ObjectBuilder<Processor> redact(RedactProcessor v) {
this._kind = Kind.Redact;
this._value = v;
return this;
}

public ObjectBuilder<Processor> redact(Function<RedactProcessor.Builder, ObjectBuilder<RedactProcessor>> fn) {
return this.redact(fn.apply(new RedactProcessor.Builder()).build());
}

public ObjectBuilder<Processor> remove(RemoveProcessor v) {
this._kind = Kind.Remove;
this._value = v;
Expand Down Expand Up @@ -1353,6 +1382,7 @@ protected static void setupProcessorDeserializer(ObjectDeserializer<Builder> op)
op.add(Builder::kv, KeyValueProcessor._DESERIALIZER, "kv");
op.add(Builder::lowercase, LowercaseProcessor._DESERIALIZER, "lowercase");
op.add(Builder::pipeline, PipelineProcessor._DESERIALIZER, "pipeline");
op.add(Builder::redact, RedactProcessor._DESERIALIZER, "redact");
op.add(Builder::remove, RemoveProcessor._DESERIALIZER, "remove");
op.add(Builder::rename, RenameProcessor._DESERIALIZER, "rename");
op.add(Builder::reroute, RerouteProcessor._DESERIALIZER, "reroute");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,24 @@ public static Processor pipeline(Function<PipelineProcessor.Builder, ObjectBuild
return builder.build();
}

/**
* Creates a builder for the {@link RedactProcessor redact} {@code Processor}
* variant.
*/
public static RedactProcessor.Builder redact() {
return new RedactProcessor.Builder();
}

/**
* Creates a Processor of the {@link RedactProcessor redact} {@code Processor}
* variant.
*/
public static Processor redact(Function<RedactProcessor.Builder, ObjectBuilder<RedactProcessor>> fn) {
Processor.Builder builder = new Processor.Builder();
builder.redact(fn.apply(new RedactProcessor.Builder()).build());
return builder.build();
}

/**
* Creates a builder for the {@link RemoveProcessor remove} {@code Processor}
* variant.
Expand Down
Loading

0 comments on commit e2912c3

Please sign in to comment.