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

feat(add-xy_shape): Ability to use xy_shape field type #885

Merged
merged 9 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This section is for maintaining a changelog for all breaking changes for the cli

### Added
- Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330))
- Add xy_shape property ([#884](https://github.com/opensearch-project/opensearch-java/pull/885))

### Dependencies

Expand All @@ -20,6 +21,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
- Deprecate RestClientTransport ([#536](https://github.com/opensearch-project/opensearch-java/pull/536))

### Removed
- Delete shape property ([#884](https://github.com/opensearch-project/opensearch-java/pull/885))

### Fixed
- Fix version and build ([#254](https://github.com/opensearch-project/opensearch-java/pull/254))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public enum FieldType implements JsonEnum {

FlatObject("flat_object"),

Shape("shape"),
XyShape("xy_shape"),

Histogram("histogram"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public enum Kind implements JsonEnum {

SearchAsYouType("search_as_you_type"),

Shape("shape"),
XyShape("xy_shape"),

Short("short"),

Expand Down Expand Up @@ -845,20 +845,20 @@ public SearchAsYouTypeProperty searchAsYouType() {
}

/**
* Is this variant instance of kind {@code shape}?
* Is this variant instance of kind {@code xy_shape}?
*/
public boolean isShape() {
return _kind == Kind.Shape;
public boolean isXyShape() {
return _kind == Kind.XyShape;
}

/**
* Get the {@code shape} variant value.
* Get the {@code xy_shape} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code shape} kind.
* if the current variant is not of the {@code xy_shape} kind.
*/
public ShapeProperty shape() {
return TaggedUnionUtils.get(this, Kind.Shape);
public XyShapeProperty xyShape() {
return TaggedUnionUtils.get(this, Kind.XyShape);
}

/**
Expand Down Expand Up @@ -1364,14 +1364,14 @@ public ObjectBuilder<Property> searchAsYouType(
return this.searchAsYouType(fn.apply(new SearchAsYouTypeProperty.Builder()).build());
}

public ObjectBuilder<Property> shape(ShapeProperty v) {
this._kind = Kind.Shape;
public ObjectBuilder<Property> xyShape(XyShapeProperty v) {
this._kind = Kind.XyShape;
this._value = v;
return this;
}

public ObjectBuilder<Property> shape(Function<ShapeProperty.Builder, ObjectBuilder<ShapeProperty>> fn) {
return this.shape(fn.apply(new ShapeProperty.Builder()).build());
public ObjectBuilder<Property> xyShape(Function<XyShapeProperty.Builder, ObjectBuilder<XyShapeProperty>> fn) {
return this.xyShape(fn.apply(new XyShapeProperty.Builder()).build());
}

public ObjectBuilder<Property> short_(ShortNumberProperty v) {
Expand Down Expand Up @@ -1483,7 +1483,7 @@ protected static void setupPropertyDeserializer(ObjectDeserializer<Builder> op)
op.add(Builder::rankFeatures, RankFeaturesProperty._DESERIALIZER, "rank_features");
op.add(Builder::scaledFloat, ScaledFloatNumberProperty._DESERIALIZER, "scaled_float");
op.add(Builder::searchAsYouType, SearchAsYouTypeProperty._DESERIALIZER, "search_as_you_type");
op.add(Builder::shape, ShapeProperty._DESERIALIZER, "shape");
op.add(Builder::xyShape, XyShapeProperty._DESERIALIZER, "xy_shape");
op.add(Builder::short_, ShortNumberProperty._DESERIALIZER, "short");
op.add(Builder::text, TextProperty._DESERIALIZER, "text");
op.add(Builder::tokenCount, TokenCountProperty._DESERIALIZER, "token_count");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ public static SearchAsYouTypeProperty.Builder searchAsYouType() {
}

/**
* Creates a builder for the {@link ShapeProperty shape} {@code Property}
* Creates a builder for the {@link XyShapeProperty xy_shape} {@code Property}
* variant.
*/
public static ShapeProperty.Builder shape() {
return new ShapeProperty.Builder();
public static XyShapeProperty.Builder xyShape() {
return new XyShapeProperty.Builder();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

package org.opensearch.client.opensearch._types.mapping;
reta marked this conversation as resolved.
Show resolved Hide resolved

// typedef: _types.mapping.XyShapeProperty

import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand All @@ -42,16 +44,14 @@
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;

// typedef: _types.mapping.ShapeProperty

/**
* The <code>shape</code> data type facilitates the indexing of and searching
* The <code>xy_shape</code> data type facilitates the indexing of and searching
* with arbitrary <code>x, y</code> cartesian shapes such as rectangles and
* polygons.
*
*/
@JsonpDeserializable
public class ShapeProperty extends DocValuesPropertyBase implements PropertyVariant {
public class XyShapeProperty extends DocValuesPropertyBase implements PropertyVariant {
@Nullable
private final Boolean coerce;

Expand All @@ -66,7 +66,7 @@ public class ShapeProperty extends DocValuesPropertyBase implements PropertyVari

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

private ShapeProperty(Builder builder) {
private XyShapeProperty(XyShapeProperty.Builder builder) {
super(builder);

this.coerce = builder.coerce;
Expand All @@ -76,16 +76,16 @@ private ShapeProperty(Builder builder) {

}

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

/**
* Property variant kind.
*/
@Override
public Property.Kind _propertyKind() {
return Property.Kind.Shape;
return Property.Kind.XyShape;
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public final GeoOrientation orientation() {

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", "shape");
generator.write("type", "xy_shape");
super.serializeInternal(generator, mapper);
if (this.coerce != null) {
generator.writeKey("coerce");
Expand All @@ -149,10 +149,12 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
// ---------------------------------------------------------------------------------------------

/**
* Builder for {@link ShapeProperty}.
* Builder for {@link XyShapeProperty}.
*/

public static class Builder extends DocValuesPropertyBase.AbstractBuilder<Builder> implements ObjectBuilder<ShapeProperty> {
public static class Builder extends DocValuesPropertyBase.AbstractBuilder<XyShapeProperty.Builder>
implements
ObjectBuilder<XyShapeProperty> {
@Nullable
private Boolean coerce;

Expand All @@ -168,69 +170,69 @@ public static class Builder extends DocValuesPropertyBase.AbstractBuilder<Builde
/**
* API name: {@code coerce}
*/
public final Builder coerce(@Nullable Boolean value) {
public final XyShapeProperty.Builder coerce(@Nullable Boolean value) {
this.coerce = value;
return this;
}

/**
* API name: {@code ignore_malformed}
*/
public final Builder ignoreMalformed(@Nullable Boolean value) {
public final XyShapeProperty.Builder ignoreMalformed(@Nullable Boolean value) {
this.ignoreMalformed = value;
return this;
}

/**
* API name: {@code ignore_z_value}
*/
public final Builder ignoreZValue(@Nullable Boolean value) {
public final XyShapeProperty.Builder ignoreZValue(@Nullable Boolean value) {
this.ignoreZValue = value;
return this;
}

/**
* API name: {@code orientation}
*/
public final Builder orientation(@Nullable GeoOrientation value) {
public final XyShapeProperty.Builder orientation(@Nullable GeoOrientation value) {
this.orientation = value;
return this;
}

@Override
protected Builder self() {
protected XyShapeProperty.Builder self() {
return this;
}

/**
* Builds a {@link ShapeProperty}.
* Builds a {@link XyShapeProperty}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public ShapeProperty build() {
public XyShapeProperty build() {
_checkSingleUse();

return new ShapeProperty(this);
return new XyShapeProperty(this);
}
}

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

/**
* Json deserializer for {@link ShapeProperty}
* Json deserializer for {@link XyShapeProperty}
*/
public static final JsonpDeserializer<ShapeProperty> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
Builder::new,
ShapeProperty::setupShapePropertyDeserializer
public static final JsonpDeserializer<XyShapeProperty> _DESERIALIZER = ObjectBuilderDeserializer.lazy(
XyShapeProperty.Builder::new,
XyShapeProperty::setupXyShapePropertyDeserializer
);

protected static void setupShapePropertyDeserializer(ObjectDeserializer<ShapeProperty.Builder> op) {
protected static void setupXyShapePropertyDeserializer(ObjectDeserializer<XyShapeProperty.Builder> op) {
DocValuesPropertyBase.setupDocValuesPropertyBaseDeserializer(op);
op.add(Builder::coerce, JsonpDeserializer.booleanDeserializer(), "coerce");
op.add(Builder::ignoreMalformed, JsonpDeserializer.booleanDeserializer(), "ignore_malformed");
op.add(Builder::ignoreZValue, JsonpDeserializer.booleanDeserializer(), "ignore_z_value");
op.add(Builder::orientation, GeoOrientation._DESERIALIZER, "orientation");
op.add(XyShapeProperty.Builder::coerce, JsonpDeserializer.booleanDeserializer(), "coerce");
op.add(XyShapeProperty.Builder::ignoreMalformed, JsonpDeserializer.booleanDeserializer(), "ignore_malformed");
op.add(XyShapeProperty.Builder::ignoreZValue, JsonpDeserializer.booleanDeserializer(), "ignore_z_value");
op.add(XyShapeProperty.Builder::orientation, GeoOrientation._DESERIALIZER, "orientation");

op.ignore("type");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public enum Kind implements JsonEnum {

ScriptScore("script_score"),

Shape("shape"),
XyShape("xy_shape"),

SimpleQueryString("simple_query_string"),

Expand Down Expand Up @@ -915,20 +915,20 @@ public ScriptScoreQuery scriptScore() {
}

/**
* Is this variant instance of kind {@code shape}?
* Is this variant instance of kind {@code xy_shape}?
*/
public boolean isShape() {
return _kind == Kind.Shape;
public boolean isXyShape() {
return _kind == Kind.XyShape;
}

/**
* Get the {@code shape} variant value.
* Get the {@code xy_shape} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code shape} kind.
* if the current variant is not of the {@code xy_shape} kind.
*/
public ShapeQuery shape() {
return TaggedUnionUtils.get(this, Kind.Shape);
public XyShapeQuery xyShape() {
return TaggedUnionUtils.get(this, Kind.XyShape);
}

/**
Expand Down Expand Up @@ -1639,16 +1639,6 @@ public ObjectBuilder<Query> scriptScore(Function<ScriptScoreQuery.Builder, Objec
return this.scriptScore(fn.apply(new ScriptScoreQuery.Builder()).build());
}

public ObjectBuilder<Query> shape(ShapeQuery v) {
this._kind = Kind.Shape;
this._value = v;
return this;
}

public ObjectBuilder<Query> shape(Function<ShapeQuery.Builder, ObjectBuilder<ShapeQuery>> fn) {
return this.shape(fn.apply(new ShapeQuery.Builder()).build());
}

public ObjectBuilder<Query> simpleQueryString(SimpleQueryStringQuery v) {
this._kind = Kind.SimpleQueryString;
this._value = v;
Expand Down Expand Up @@ -1858,7 +1848,6 @@ protected static void setupQueryDeserializer(ObjectDeserializer<Builder> op) {
op.add(Builder::regexp, RegexpQuery._DESERIALIZER, "regexp");
op.add(Builder::script, ScriptQuery._DESERIALIZER, "script");
op.add(Builder::scriptScore, ScriptScoreQuery._DESERIALIZER, "script_score");
op.add(Builder::shape, ShapeQuery._DESERIALIZER, "shape");
op.add(Builder::simpleQueryString, SimpleQueryStringQuery._DESERIALIZER, "simple_query_string");
op.add(Builder::spanContaining, SpanContainingQuery._DESERIALIZER, "span_containing");
op.add(Builder::fieldMaskingSpan, SpanFieldMaskingQuery._DESERIALIZER, "field_masking_span");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ public static ScriptScoreQuery.Builder scriptScore() {
}

/**
* Creates a builder for the {@link ShapeQuery shape} {@code Query} variant.
* Creates a builder for the {@link XyShapeQuery xy_shape} {@code Query} variant.
*/
public static ShapeQuery.Builder shape() {
return new ShapeQuery.Builder();
public static XyShapeQuery.Builder xyShape() {
return new XyShapeQuery.Builder();
}

/**
Expand Down
Loading
Loading