Skip to content

Commit 753c028

Browse files
authored
Guard for adding null value tags to vector tiles (#87051) (#87056)
This commit adds a guard so tags with null values are ignored.
1 parent e18fae6 commit 753c028

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

docs/changelog/87051.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 87051
2+
summary: Guard for adding null value tags to vector tiles
3+
area: Geo
4+
type: bug
5+
issues: []

x-pack/plugin/vector-tile/src/javaRestTest/java/org/elasticsearch/xpack/vectortile/VectorTileRestIT.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ private void createIndexAndPutGeometry(String indexName, Geometry geometry, Stri
120120
},
121121
"name": {
122122
"type": "keyword"
123+
},
124+
"ignore_value": {
125+
"type": "double",
126+
"ignore_malformed" : true
123127
}
124128
}
125129
}""");
@@ -129,7 +133,7 @@ private void createIndexAndPutGeometry(String indexName, Geometry geometry, Stri
129133
final Request putRequest = new Request(HttpPost.METHOD_NAME, indexName + "/_doc/" + id);
130134
putRequest.setJsonEntity("""
131135
{
132-
"location": "%s", "name": "geometry", "value1": %s, "value2": %s, "nullField" : null
136+
"location": "%s", "name": "geometry", "value1": %s, "value2": %s, "nullField" : null, "ignore_value" : ""
133137
}""".formatted(WellKnownText.toWKT(geometry), 1, 2));
134138
response = client().performRequest(putRequest);
135139
assertThat(response.getStatusLine().getStatusCode(), Matchers.equalTo(HttpStatus.SC_CREATED));
@@ -653,6 +657,16 @@ public void testWithNullFields() throws Exception {
653657
assertLayer(tile, META_LAYER, 4096, 1, 13);
654658
}
655659

660+
public void testWithIgnoreMalformedValueFields() throws Exception {
661+
final Request mvtRequest = new Request(getHttpMethod(), INDEX_POLYGON + "/_mvt/location/" + z + "/" + x + "/" + y);
662+
mvtRequest.setJsonEntity("{\"fields\": [ \"ignore_value\"] }");
663+
final VectorTile.Tile tile = execute(mvtRequest);
664+
assertThat(tile.getLayersCount(), Matchers.equalTo(3));
665+
assertLayer(tile, HITS_LAYER, 4096, 1, 2);
666+
assertLayer(tile, AGGS_LAYER, 4096, 256 * 256, 2);
667+
assertLayer(tile, META_LAYER, 4096, 1, 13);
668+
}
669+
656670
public void testWithFieldsWildCard() throws Exception {
657671
final Request mvtRequest = new Request(getHttpMethod(), INDEX_POLYGON + "/_mvt/location/" + z + "/" + x + "/" + y);
658672
mvtRequest.setJsonEntity("{\"fields\": [\"*\"] }");

x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/rest/VectorTileUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public static void addToXContentToFeature(VectorTile.Tile.Feature.Builder featur
6060
* Adds the provided key / value pair into the feature as tags.
6161
*/
6262
public static void addPropertyToFeature(VectorTile.Tile.Feature.Builder feature, MvtLayerProps layerProps, String key, Object value) {
63+
if (value == null) {
64+
// guard for null values
65+
return;
66+
}
6367
feature.addTags(layerProps.addKey(key));
6468
feature.addTags(layerProps.addValue(value));
6569
}

0 commit comments

Comments
 (0)