Skip to content

Commit

Permalink
Address shape query builders testToQuery failures (#119096)
Browse files Browse the repository at this point in the history
With broadening of index versions tested in AbstractQueryBuilder, we need to
restore compatibility with 7x index versions that has been removed.

Closes #119090
Closes #119091
  • Loading branch information
javanna authored Dec 19, 2024
1 parent 0a7d50d commit 6983f9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@ tests:
issue: https://github.com/elastic/elasticsearch/issues/118414
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlClientYamlIT
issue: https://github.com/elastic/elasticsearch/issues/119086
- class: org.elasticsearch.xpack.spatial.index.query.ShapeQueryBuilderOverShapeTests
method: testToQuery
issue: https://github.com/elastic/elasticsearch/issues/119090
- class: org.elasticsearch.xpack.spatial.index.query.GeoShapeQueryBuilderGeoShapeTests
method: testToQuery
issue: https://github.com/elastic/elasticsearch/issues/119091

# Examples:
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.ShapeType;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
import org.elasticsearch.index.query.SearchExecutionContext;
Expand Down Expand Up @@ -87,15 +88,27 @@ protected GeoShapeQueryBuilder doCreateTestQueryBuilder(boolean indexedShape) {
}
if (ESTestCase.randomBoolean()) {
SearchExecutionContext context = AbstractBuilderTestCase.createSearchExecutionContext();
if (shapeType == ShapeType.LINESTRING || shapeType == ShapeType.MULTILINESTRING) {
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS));
if (context.indexVersionCreated().onOrAfter(IndexVersions.V_7_5_0)) { // CONTAINS is only supported from version 7.5
if (shapeType == ShapeType.LINESTRING || shapeType == ShapeType.MULTILINESTRING) {
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS));
} else {
builder.relation(
ESTestCase.randomFrom(
ShapeRelation.DISJOINT,
ShapeRelation.INTERSECTS,
ShapeRelation.WITHIN,
ShapeRelation.CONTAINS
)
);
}
} else {
builder.relation(
ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN, ShapeRelation.CONTAINS)
);
if (shapeType == ShapeType.LINESTRING || shapeType == ShapeType.MULTILINESTRING) {
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS));
} else {
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN));
}
}
}

if (ESTestCase.randomBoolean()) {
builder.ignoreUnmapped(ESTestCase.randomBoolean());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.geo.ShapeTestUtils;
import org.elasticsearch.geometry.Geometry;
import org.elasticsearch.geometry.ShapeType;
import org.elasticsearch.index.IndexVersions;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.SearchExecutionContext;

Expand All @@ -32,10 +33,18 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
@Override
protected ShapeRelation getShapeRelation(ShapeType type) {
SearchExecutionContext context = createSearchExecutionContext();
if (type == ShapeType.LINESTRING || type == ShapeType.MULTILINESTRING) {
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS);
if (context.indexVersionCreated().onOrAfter(IndexVersions.V_7_5_0)) { // CONTAINS is only supported from version 7.5
if (type == ShapeType.LINESTRING || type == ShapeType.MULTILINESTRING) {
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS);
} else {
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN, ShapeRelation.CONTAINS);
}
} else {
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN, ShapeRelation.CONTAINS);
if (type == ShapeType.LINESTRING || type == ShapeType.MULTILINESTRING) {
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS);
} else {
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN);
}
}
}

Expand Down

0 comments on commit 6983f9a

Please sign in to comment.