kopia lustrzana https://github.com/onthegomap/planetiler
Fix handling of string typed null values (#987)
* Added unit test for handling of missing (e.g. null) values - When missing item is NOT typed, than it is properly handld as null, e.g. it is NOT included in the generated feature - When missing item is typed to 'string', it gets converted into "null" string value hence generated featire has attribute non_existent_typed=null * Fixed handling of missing or null values for attributes with type 'string' * clean-up: removed unused importpull/994/head
rodzic
b0118d9ed8
commit
d2efc1a4fe
|
|
@ -2,7 +2,6 @@ package com.onthegomap.planetiler.expression;
|
|||
|
||||
import com.onthegomap.planetiler.reader.WithTags;
|
||||
import com.onthegomap.planetiler.util.Parse;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
|
|
@ -10,7 +9,7 @@ import java.util.function.UnaryOperator;
|
|||
* Destination data types for an attribute that link the type to functions that can parse the value from an input object
|
||||
*/
|
||||
public enum DataType implements BiFunction<WithTags, String, Object> {
|
||||
GET_STRING("string", WithTags::getString, Objects::toString),
|
||||
GET_STRING("string", WithTags::getString, Parse::parseStringOrNull),
|
||||
GET_BOOLEAN("boolean", WithTags::getBoolean, Parse::bool),
|
||||
GET_DIRECTION("direction", WithTags::getDirection, Parse::direction),
|
||||
GET_LONG("long", WithTags::getLong, Parse::parseLongOrNull),
|
||||
|
|
|
|||
|
|
@ -31,6 +31,11 @@ public class Parse {
|
|||
|
||||
private Parse() {}
|
||||
|
||||
/** Returns {@code tag} as a string or null if null. */
|
||||
public static String parseStringOrNull(Object tag) {
|
||||
return tag == null ? null : tag.toString();
|
||||
}
|
||||
|
||||
/** Returns {@code tag} as a long or null if invalid. */
|
||||
public static Long parseLongOrNull(Object tag) {
|
||||
return tag == null ? null : tag instanceof Number number ? Long.valueOf(number.longValue()) :
|
||||
|
|
|
|||
|
|
@ -267,6 +267,15 @@ class ConfiguredFeatureTest {
|
|||
}, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTagNullValueAttributeTest() {
|
||||
testPolygon(TEST_RESOURCE, "tag_attribute_null.yml", waterTags, f -> {
|
||||
var attr = f.getAttrsAtZoom(14);
|
||||
assertNull(attr.get("non_existent"));
|
||||
assertNull(attr.get("non_existent_typed"));
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTagIncludeAttributeTest() {
|
||||
testPolygon(TEST_RESOURCE, "tag_include.yml", waterTags, f -> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
schema_name: Test Case Schema
|
||||
schema_description: Test case tile schema
|
||||
attribution: Test attribution
|
||||
sources:
|
||||
osm:
|
||||
type: osm
|
||||
url: geofabrik:rhode-island
|
||||
layers:
|
||||
- id: testLayer
|
||||
features:
|
||||
- source:
|
||||
- osm
|
||||
geometry: polygon
|
||||
include_when:
|
||||
natural: water
|
||||
attributes:
|
||||
- key: non_existent
|
||||
- key: non_existent_typed
|
||||
type: string
|
||||
Ładowanie…
Reference in New Issue