Skip to content

Commit

Permalink
Guard for adding null value tags to vector tiles (#87051) (#87056)
Browse files Browse the repository at this point in the history
This commit adds a guard so tags with null values are ignored.
  • Loading branch information
iverase committed May 23, 2022
1 parent e18fae6 commit 753c028
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/87051.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 87051
summary: Guard for adding null value tags to vector tiles
area: Geo
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ private void createIndexAndPutGeometry(String indexName, Geometry geometry, Stri
},
"name": {
"type": "keyword"
},
"ignore_value": {
"type": "double",
"ignore_malformed" : true
}
}
}""");
Expand All @@ -129,7 +133,7 @@ private void createIndexAndPutGeometry(String indexName, Geometry geometry, Stri
final Request putRequest = new Request(HttpPost.METHOD_NAME, indexName + "/_doc/" + id);
putRequest.setJsonEntity("""
{
"location": "%s", "name": "geometry", "value1": %s, "value2": %s, "nullField" : null
"location": "%s", "name": "geometry", "value1": %s, "value2": %s, "nullField" : null, "ignore_value" : ""
}""".formatted(WellKnownText.toWKT(geometry), 1, 2));
response = client().performRequest(putRequest);
assertThat(response.getStatusLine().getStatusCode(), Matchers.equalTo(HttpStatus.SC_CREATED));
Expand Down Expand Up @@ -653,6 +657,16 @@ public void testWithNullFields() throws Exception {
assertLayer(tile, META_LAYER, 4096, 1, 13);
}

public void testWithIgnoreMalformedValueFields() throws Exception {
final Request mvtRequest = new Request(getHttpMethod(), INDEX_POLYGON + "/_mvt/location/" + z + "/" + x + "/" + y);
mvtRequest.setJsonEntity("{\"fields\": [ \"ignore_value\"] }");
final VectorTile.Tile tile = execute(mvtRequest);
assertThat(tile.getLayersCount(), Matchers.equalTo(3));
assertLayer(tile, HITS_LAYER, 4096, 1, 2);
assertLayer(tile, AGGS_LAYER, 4096, 256 * 256, 2);
assertLayer(tile, META_LAYER, 4096, 1, 13);
}

public void testWithFieldsWildCard() throws Exception {
final Request mvtRequest = new Request(getHttpMethod(), INDEX_POLYGON + "/_mvt/location/" + z + "/" + x + "/" + y);
mvtRequest.setJsonEntity("{\"fields\": [\"*\"] }");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public static void addToXContentToFeature(VectorTile.Tile.Feature.Builder featur
* Adds the provided key / value pair into the feature as tags.
*/
public static void addPropertyToFeature(VectorTile.Tile.Feature.Builder feature, MvtLayerProps layerProps, String key, Object value) {
if (value == null) {
// guard for null values
return;
}
feature.addTags(layerProps.addKey(key));
feature.addTags(layerProps.addValue(value));
}
Expand Down

0 comments on commit 753c028

Please sign in to comment.