Skip to content

Commit

Permalink
feat(add-xy_shape): Ability to use xy_shape field type (opensearch-pr…
Browse files Browse the repository at this point in the history
…oject#885)

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

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* update changelog

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* Fix changelog and add license header

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* updated license header

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* remove shape property

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* fix test after removing shape

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* adapt ShapeQuery test to XyShapeQuery

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* Add ES license headers

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

* Add ES license headers on tests

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>

---------

Signed-off-by: MESSAOUDI Khadidja <kmessaoudi@thefork.com>
(cherry picked from commit ccdb56a)
  • Loading branch information
kmessaoudi committed Mar 19, 2024
1 parent 5eb59a9 commit 7480de5
Show file tree
Hide file tree
Showing 15 changed files with 228 additions and 181 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased 2.x]
### Added
- Add xy_shape property ([#884](https://github.com/opensearch-project/opensearch-java/pull/885))

### Dependencies
- Bumps `io.github.classgraph:classgraph` from 4.8.161 to 4.8.165
Expand All @@ -15,6 +16,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Deprecated

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

### Fixed
- Fix integer overflow for variables in indices stats response ([#877](https://github.com/opensearch-project/opensearch-java/pull/877))
Expand Down Expand Up @@ -322,4 +324,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[2.5.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.4.0...v2.5.0
[2.4.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.3.0...v2.4.0
[2.3.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0
[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0
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;

// 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

0 comments on commit 7480de5

Please sign in to comment.