Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Fixed
- Fix `unitTest` task not running the tests in the `test` source set ([#2074](https://github.com/opensearch-project/opensearch-java/pull/2074))
- Allow pre-indexed shape queries by making `shape` optional on `GeoShapeQueryField` and `XyShapeQueryField` ([#2011](https://github.com/opensearch-project/opensearch-java/issues/2011))

## [Unreleased 3.x]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.opensearch._types.GeoShapeRelation;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.CopyableBuilder;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
Expand All @@ -67,15 +66,15 @@ public class GeoShapeQueryField implements PlainJsonSerializable, ToCopyableBuil
@Nullable
private final GeoShapeRelation relation;

@Nonnull
@Nullable
private final GeoShape shape;

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

private GeoShapeQueryField(Builder builder) {
this.indexedShape = builder.indexedShape;
this.relation = builder.relation;
this.shape = ApiTypeHelper.requireNonNull(builder.shape, this, "shape");
this.shape = builder.shape;
}

public static GeoShapeQueryField of(Function<GeoShapeQueryField.Builder, ObjectBuilder<GeoShapeQueryField>> fn) {
Expand All @@ -99,9 +98,9 @@ public final GeoShapeRelation relation() {
}

/**
* Required - API name: {@code shape}
* API name: {@code shape}
*/
@Nonnull
@Nullable
public final GeoShape shape() {
return this.shape;
}
Expand All @@ -127,8 +126,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
this.relation.serialize(generator, mapper);
}

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

// ---------------------------------------------------------------------------------------------
Expand All @@ -152,6 +153,7 @@ public static class Builder extends ObjectBuilderBase implements CopyableBuilder
private FieldLookup indexedShape;
@Nullable
private GeoShapeRelation relation;
@Nullable
private GeoShape shape;

public Builder() {}
Expand Down Expand Up @@ -201,16 +203,16 @@ public final Builder relation(@Nullable GeoShapeRelation value) {
}

/**
* Required - API name: {@code shape}
* API name: {@code shape}
*/
@Nonnull
public final Builder shape(GeoShape value) {
public final Builder shape(@Nullable GeoShape value) {
this.shape = value;
return this;
}

/**
* Required - API name: {@code shape}
* API name: {@code shape}
*/
@Nonnull
public final Builder shape(Function<GeoShape.Builder, ObjectBuilder<GeoShape>> fn) {
Expand Down Expand Up @@ -252,7 +254,7 @@ public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.indexedShape);
result = 31 * result + Objects.hashCode(this.relation);
result = 31 * result + this.shape.hashCode();
result = 31 * result + Objects.hashCode(this.shape);
return result;
}

Expand All @@ -263,6 +265,6 @@ public boolean equals(Object o) {
GeoShapeQueryField other = (GeoShapeQueryField) o;
return Objects.equals(this.indexedShape, other.indexedShape)
&& Objects.equals(this.relation, other.relation)
&& this.shape.equals(other.shape);
&& Objects.equals(this.shape, other.shape);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.opensearch.client.json.ObjectDeserializer;
import org.opensearch.client.json.PlainJsonSerializable;
import org.opensearch.client.opensearch._types.GeoShapeRelation;
import org.opensearch.client.util.ApiTypeHelper;
import org.opensearch.client.util.CopyableBuilder;
import org.opensearch.client.util.ObjectBuilder;
import org.opensearch.client.util.ObjectBuilderBase;
Expand All @@ -43,15 +42,15 @@ public class XyShapeQueryField implements PlainJsonSerializable, ToCopyableBuild
@Nullable
private final GeoShapeRelation relation;

@Nonnull
@Nullable
private final XyShape shape;

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

private XyShapeQueryField(Builder builder) {
this.indexedShape = builder.indexedShape;
this.relation = builder.relation;
this.shape = ApiTypeHelper.requireNonNull(builder.shape, this, "shape");
this.shape = builder.shape;
}

public static XyShapeQueryField of(Function<XyShapeQueryField.Builder, ObjectBuilder<XyShapeQueryField>> fn) {
Expand All @@ -75,9 +74,9 @@ public final GeoShapeRelation relation() {
}

/**
* Required - API name: {@code shape}
* API name: {@code shape}
*/
@Nonnull
@Nullable
public final XyShape shape() {
return this.shape;
}
Expand All @@ -103,8 +102,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
this.relation.serialize(generator, mapper);
}

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

// ---------------------------------------------------------------------------------------------
Expand All @@ -128,6 +129,7 @@ public static class Builder extends ObjectBuilderBase implements CopyableBuilder
private FieldLookup indexedShape;
@Nullable
private GeoShapeRelation relation;
@Nullable
private XyShape shape;

public Builder() {}
Expand Down Expand Up @@ -177,16 +179,16 @@ public final Builder relation(@Nullable GeoShapeRelation value) {
}

/**
* Required - API name: {@code shape}
* API name: {@code shape}
*/
@Nonnull
public final Builder shape(XyShape value) {
public final Builder shape(@Nullable XyShape value) {
this.shape = value;
return this;
}

/**
* Required - API name: {@code shape}
* API name: {@code shape}
*/
@Nonnull
public final Builder shape(Function<XyShape.Builder, ObjectBuilder<XyShape>> fn) {
Expand Down Expand Up @@ -228,7 +230,7 @@ public int hashCode() {
int result = 17;
result = 31 * result + Objects.hashCode(this.indexedShape);
result = 31 * result + Objects.hashCode(this.relation);
result = 31 * result + this.shape.hashCode();
result = 31 * result + Objects.hashCode(this.shape);
return result;
}

Expand All @@ -239,6 +241,6 @@ public boolean equals(Object o) {
XyShapeQueryField other = (XyShapeQueryField) o;
return Objects.equals(this.indexedShape, other.indexedShape)
&& Objects.equals(this.relation, other.relation)
&& this.shape.equals(other.shape);
&& Objects.equals(this.shape, other.shape);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ public void toBuilder() {

assertEquals(toJson(copied), toJson(origin));
}

@Test
public void indexedShapeOnly() {
GeoShapeQueryField field = new GeoShapeQueryField.Builder().indexedShape(i -> i.id("id").index("shapes").path("location")).build();

assertNull(field.shape());
assertEquals("id", field.indexedShape().id());
assertEquals("{\"indexed_shape\":{\"id\":\"id\",\"index\":\"shapes\",\"path\":\"location\"}}", toJson(field));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ public void toBuilder() {

assertEquals(toJson(copied), toJson(origin));
}

@Test
public void indexedShapeOnly() {
XyShapeQueryField field = new XyShapeQueryField.Builder().indexedShape(i -> i.id("id").index("shapes").path("location")).build();

assertNull(field.shape());
assertEquals("id", field.indexedShape().id());
assertEquals("{\"indexed_shape\":{\"id\":\"id\",\"index\":\"shapes\",\"path\":\"location\"}}", toJson(field));
}
}
4 changes: 0 additions & 4 deletions java-codegen/opensearch-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48620,8 +48620,6 @@ components:
$ref: '#/components/schemas/_common.query_dsl___GeoShape'
relation:
$ref: '#/components/schemas/_common___GeoShapeRelation'
required:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @arimu1 , please submit a pull request against https://github.com/OpenSearch-project/openSearch-api-specification

- shape
_common.query_dsl___GeoValidationMethod:
type: string
enum:
Expand Down Expand Up @@ -50318,8 +50316,6 @@ components:
$ref: '#/components/schemas/_common.query_dsl___XyShape'
relation:
$ref: '#/components/schemas/_common___GeoShapeRelation'
required:
- shape
_common.query_dsl___ZeroTermsQuery:
type: string
enum:
Expand Down
Loading