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

[BUG] Some GeoShapeQueryBuilder instances cannot be toString()'d #12324

Open
andrross opened this issue Feb 14, 2024 · 3 comments · Fixed by #12834
Open

[BUG] Some GeoShapeQueryBuilder instances cannot be toString()'d #12324

andrross opened this issue Feb 14, 2024 · 3 comments · Fixed by #12834
Labels
bug Something isn't working Geospatial Other v2.14.0 v3.0.0 Issues and PRs related to version 3.0.0

Comments

@andrross
Copy link
Member

Describe the bug

Executing this line of code will always fail:

new GeoShapeQueryBuilder("test", new LinearRing(new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 })).toString();

The specific case where this is known to be problematic is if TRACE logging is enabled and the TaskManager attempts to log a query containing a linear ring instance. See #11688 for a case where somehow trace logging was enabled in the CI system which resulted in failing tests. For example:

java.lang.UnsupportedOperationException: line ring cannot be serialized using GeoJson
	at __randomizedtesting.SeedInfo.seed([D24747E5E9B452AE:CFF1D9D2D64D1980]:0)
	at org.opensearch.common.geo.GeoJson$3.visit(GeoJson.java:561)
	at org.opensearch.common.geo.GeoJson$3.visit(GeoJson.java:543)
	at org.opensearch.geometry.LinearRing.visit(LinearRing.java:84)
	at org.opensearch.common.geo.GeoJson.getGeoJsonName(GeoJson.java:543)
	at org.opensearch.common.geo.GeoJson.toXContent(GeoJson.java:103)
	at org.opensearch.index.query.AbstractGeometryQueryBuilder.doXContent(AbstractGeometryQueryBuilder.java:452)
	at org.opensearch.index.query.AbstractQueryBuilder.toXContent(AbstractQueryBuilder.java:101)
	at org.opensearch.core.xcontent.XContentBuilder.value(XContentBuilder.java:887)
	at org.opensearch.core.xcontent.XContentBuilder.value(XContentBuilder.java:880)
	at org.opensearch.core.xcontent.XContentBuilder.field(XContentBuilder.java:872)
	at org.opensearch.search.builder.SearchSourceBuilder.innerToXContent(SearchSourceBuilder.java:1350)
	at org.opensearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:1490)
	at org.opensearch.core.xcontent.XContentHelper.toXContent(XContentHelper.java:46)
	at org.opensearch.search.builder.SearchSourceBuilder.toString(SearchSourceBuilder.java:1810)
	at org.opensearch.action.search.SearchRequest.buildDescription(SearchRequest.java:715)
	at org.opensearch.action.search.SearchTask.getDescription(SearchTask.java:83)
	at org.opensearch.tasks.TaskManager.register(TaskManager.java:210)
	at org.opensearch.action.support.TransportAction.execute(TransportAction.java:99)

Related component

Other

To Reproduce

Add the following unit test to GeoShapeQueryBuilderGeoShapeTests:

public void testToString() {
    new GeoShapeQueryBuilder("test", new LinearRing(new double[] { 0, 0, 0 }, new double[] { 0, 0, 0 })).toString();
}

Expected behavior

toString() should never fail for a valid object.

Additional Details

The base AbstractQueryBuilder implements toString() as:

@Override
public final String toString() {
    return Strings.toString(MediaTypeRegistry.JSON, this, true, true);
}

Strings.toString() convents the given instance to XContent then invokes toString on the XContentBuilder. The class AbstractGeometryQueryBuilder ultimately implements toXContent as GeoJson, and the LinearRing type cannot be converted to GeoJson.

@andrross andrross added bug Something isn't working untriaged Geospatial labels Feb 14, 2024
@github-actions github-actions bot added the Other label Feb 14, 2024
@peternied
Copy link
Member

[Triage - attendees 1 2 3 4 5 6]
@andrross Thanks for filing, happy to review a pull request to address this issue.

@peternied
Copy link
Member

@andrross I don't think this issue is resolved - the error will still happen with #12834 merged, what do you think?

@dblock
Copy link
Member

dblock commented Mar 22, 2024

LinearRing lacks serialization support, the fix for this would be #12831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Geospatial Other v2.14.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants