Skip to content
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

Generate aggregation types #1392

Merged
merged 6 commits into from
Jan 20, 2025
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
20 changes: 19 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,22 @@ After:
- The `file` property has been removed as it is not supported by OpenSearch.

### SearchShardsRequest
- The `routing` property is now of type `List<String>` instead of `String`.
- The `routing` property is now of type `List<String>` instead of `String`.

### CompositeAggregation
- The `after` property is now of type `Map<String, FieldValue>` instead of `Map<String, String>`.

### CompositeDateHistogramAggregationSource
- The `offset` property has been corrected to be of type `Time` instead of `Long`.

### CompositeValuesSource
- The `format` property has been removed as it only applies to certain subclasses.

### InferenceConfig
- The `InferenceConfig` class has been changed to a tagged union.

### SignificantTermsAggregation
- The `include` property is now of type `TermsInclude` instead of `List<String>`.

### SignificantTextAggregation
- The `include` property is now of type `TermsInclude` instead of `List<String>`.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch._types;

import jakarta.json.stream.JsonGenerator;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Generated;
import javax.annotation.Nonnull;
import org.opensearch.client.json.JsonpDeserializable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.JsonpSerializable;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.json.UnionDeserializer;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.ObjectBuilder;
Expand All @@ -48,17 +56,18 @@
// typedef: _types.GeoHashPrecision

/**
* A precision that can be expressed as a geohash length between 1 and 12, or a
* distance measure like &quot;1km&quot;, &quot;10m&quot;.
*
* The level of geohash precision, which can be expressed as a geohash length between 1 and 12 or as a distance measure, such as
* &quot;1km&quot; or &quot;10m&quot;.
*/
@JsonpDeserializable
public class GeoHashPrecision implements TaggedUnion<GeoHashPrecision.Kind, Object>, JsonpSerializable {

@Generated("org.opensearch.client.codegen.CodeGenerator")
public class GeoHashPrecision implements TaggedUnion<GeoHashPrecision.Kind, Object>, PlainJsonSerializable {
/**
* {@link GeoHashPrecision} variant kinds.
*/
public enum Kind {
GeohashLength,
Distance

Distance,
GeohashLength
}

private final Kind _kind;
Expand All @@ -79,61 +88,56 @@ private GeoHashPrecision(Kind kind, Object value) {
this._value = value;
}

private GeoHashPrecision(Builder builder) {
this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");
}

public static GeoHashPrecision of(Function<GeoHashPrecision.Builder, ObjectBuilder<GeoHashPrecision>> fn) {
return fn.apply(new Builder()).build();
}

public String _toJsonString() {
switch (_kind) {
case GeohashLength:
return this.geohashLength().toString();
case Distance:
return this.distance();

case GeohashLength:
return String.valueOf(this.geohashLength());
default:
throw new IllegalStateException("Unknown kind " + _kind);
}
}

private GeoHashPrecision(Builder builder) {

this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");

}

public static GeoHashPrecision of(Function<Builder, ObjectBuilder<GeoHashPrecision>> fn) {
return fn.apply(new Builder()).build();
}

/**
* Is this variant instance of kind {@code geohash_length}?
* Is this variant instance of kind {@code distance}?
*/
public boolean isGeohashLength() {
return _kind == Kind.GeohashLength;
public boolean isDistance() {
return _kind == Kind.Distance;
}

/**
* Get the {@code geohash_length} variant value.
* Get the {@code distance} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code geohash_length} kind.
* @throws IllegalStateException if the current variant is not the {@code distance} kind.
*/
public Number geohashLength() {
return TaggedUnionUtils.get(this, Kind.GeohashLength);
public String distance() {
return TaggedUnionUtils.get(this, Kind.Distance);
}

/**
* Is this variant instance of kind {@code distance}?
* Is this variant instance of kind {@code geohash_length}?
*/
public boolean isDistance() {
return _kind == Kind.Distance;
public boolean isGeohashLength() {
return _kind == Kind.GeohashLength;
}

/**
* Get the {@code distance} variant value.
* Get the {@code geohash_length} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code distance} kind.
* @throws IllegalStateException if the current variant is not the {@code geohash_length} kind.
*/
public String distance() {
return TaggedUnionUtils.get(this, Kind.Distance);
public Integer geohashLength() {
return TaggedUnionUtils.get(this, Kind.GeohashLength);
}

@Override
Expand All @@ -142,27 +146,35 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {
((JsonpSerializable) _value).serialize(generator, mapper);
} else {
switch (_kind) {
case GeohashLength:
generator.write(((Number) this._value).doubleValue());

break;
case Distance:
generator.write(((String) this._value));

break;
case GeohashLength:
generator.write(((Integer) this._value));
break;
}
}
}

@Nonnull
public Builder toBuilder() {
return new Builder(this);
}

@Nonnull
public static Builder builder() {
return new Builder();
}

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<GeoHashPrecision> {
private Kind _kind;
private Object _value;

public ObjectBuilder<GeoHashPrecision> geohashLength(Number v) {
this._kind = Kind.GeohashLength;
this._value = v;
return this;
public Builder() {}

private Builder(GeoHashPrecision o) {
this._kind = o._kind;
this._value = o._value;
}

public ObjectBuilder<GeoHashPrecision> distance(String v) {
Expand All @@ -171,21 +183,43 @@ public ObjectBuilder<GeoHashPrecision> distance(String v) {
return this;
}

public ObjectBuilder<GeoHashPrecision> geohashLength(Integer v) {
this._kind = Kind.GeohashLength;
this._value = v;
return this;
}

@Override
public GeoHashPrecision build() {
_checkSingleUse();
return new GeoHashPrecision(this);
}

}

private static JsonpDeserializer<GeoHashPrecision> buildGeoHashPrecisionDeserializer() {
return new UnionDeserializer.Builder<GeoHashPrecision, Kind, Object>(GeoHashPrecision::new, false).addMember(
Kind.GeohashLength,
JsonpDeserializer.numberDeserializer()
).addMember(Kind.Distance, JsonpDeserializer.stringDeserializer()).build();
Kind.Distance,
JsonpDeserializer.stringDeserializer()
).addMember(Kind.GeohashLength, JsonpDeserializer.integerDeserializer()).build();
}

public static final JsonpDeserializer<GeoHashPrecision> _DESERIALIZER = JsonpDeserializer.lazy(
GeoHashPrecision::buildGeoHashPrecisionDeserializer
);

@Override
public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this._kind);
result = 31 * result + Objects.hashCode(this._value);
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || this.getClass() != o.getClass()) return false;
GeoHashPrecision other = (GeoHashPrecision) o;
return Objects.equals(this._kind, other._kind) && Objects.equals(this._value, other._value);
}
}
Loading
Loading