Skip to content

Commit

Permalink
feat(add-xy_shape): Ability to use xy_shape field type
Browse files Browse the repository at this point in the history
Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>
  • Loading branch information
kmessaoudi committed Mar 7, 2024
1 parent 045c805 commit d4a64ac
Show file tree
Hide file tree
Showing 12 changed files with 642 additions and 0 deletions.
1 change: 1 addition & 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public enum FieldType implements JsonEnum {

Shape("shape"),

XyShape("xy_shape"),

Histogram("histogram"),

ConstantKeyword("constant_keyword"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public enum Kind implements JsonEnum {

Shape("shape"),

XyShape("xy_shape"),

Short("short"),

Text("text"),
Expand Down Expand Up @@ -861,6 +863,23 @@ public ShapeProperty shape() {
return TaggedUnionUtils.get(this, Kind.Shape);
}

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

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

/**
* Is this variant instance of kind {@code short}?
*/
Expand Down Expand Up @@ -1374,6 +1393,16 @@ public ObjectBuilder<Property> shape(Function<ShapeProperty.Builder, ObjectBuild
return this.shape(fn.apply(new ShapeProperty.Builder()).build());
}

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

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) {
this._kind = Kind.Short;
this._value = v;
Expand Down Expand Up @@ -1484,6 +1513,7 @@ protected static void setupPropertyDeserializer(ObjectDeserializer<Builder> op)
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 @@ -339,6 +339,14 @@ public static ShapeProperty.Builder shape() {
return new ShapeProperty.Builder();
}

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

/**
* Creates a builder for the {@link ShortNumberProperty short} {@code Property}
* variant.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
package org.opensearch.client.opensearch._types.mapping;

// typedef: _types.mapping.XyShapeProperty

import jakarta.json.stream.JsonGenerator;
import java.util.function.Function;
import javax.annotation.Nullable;
import org.opensearch.client.json.JsonpDeserializer;
import org.opensearch.client.json.JsonpMapper;
import org.opensearch.client.json.ObjectBuilderDeserializer;
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.util.ObjectBuilder;

/**
* 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.
*
*/
public class XyShapeProperty extends DocValuesPropertyBase implements PropertyVariant {
@Nullable
private final Boolean coerce;

@Nullable
private final Boolean ignoreMalformed;

@Nullable
private final Boolean ignoreZValue;

@Nullable
private final GeoOrientation orientation;

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

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

this.coerce = builder.coerce;
this.ignoreMalformed = builder.ignoreMalformed;
this.ignoreZValue = builder.ignoreZValue;
this.orientation = builder.orientation;

}

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.XyShape;
}

/**
* API name: {@code coerce}
*/
@Nullable
public final Boolean coerce() {
return this.coerce;
}

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

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

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

protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {

generator.write("type", "xy_shape");
super.serializeInternal(generator, mapper);
if (this.coerce != null) {
generator.writeKey("coerce");
generator.write(this.coerce);

}
if (this.ignoreMalformed != null) {
generator.writeKey("ignore_malformed");
generator.write(this.ignoreMalformed);

}
if (this.ignoreZValue != null) {
generator.writeKey("ignore_z_value");
generator.write(this.ignoreZValue);

}
if (this.orientation != null) {
generator.writeKey("orientation");
this.orientation.serialize(generator, mapper);
}

}

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

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

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

@Nullable
private Boolean ignoreMalformed;

@Nullable
private Boolean ignoreZValue;

@Nullable
private GeoOrientation orientation;

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

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

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

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

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

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

return new XyShapeProperty(this);
}
}

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

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

protected static void setupXyShapePropertyDeserializer(ObjectDeserializer<XyShapeProperty.Builder> op) {
DocValuesPropertyBase.setupDocValuesPropertyBaseDeserializer(op);
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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public enum Kind implements JsonEnum {

Shape("shape"),

XyShape("xy_shape"),

SimpleQueryString("simple_query_string"),

SpanContaining("span_containing"),
Expand Down Expand Up @@ -931,6 +933,23 @@ public ShapeQuery shape() {
return TaggedUnionUtils.get(this, Kind.Shape);
}

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

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

/**
* Is this variant instance of kind {@code simple_query_string}?
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ public static ShapeQuery.Builder shape() {
return new ShapeQuery.Builder();
}

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

/**
* Creates a builder for the {@link SimpleQueryStringQuery simple_query_string}
* {@code Query} variant.
Expand Down
Loading

0 comments on commit d4a64ac

Please sign in to comment.