kopia lustrzana https://github.com/onthegomap/planetiler
Fix expression issues (#1030)
rodzic
9f76124ce8
commit
e6352a16a9
|
@ -19,7 +19,8 @@
|
|||
<geotools.version>32.0</geotools.version>
|
||||
<log4j.version>2.24.0</log4j.version>
|
||||
<prometheus.version>0.16.0</prometheus.version>
|
||||
<protobuf.version>4.28.2</protobuf.version>
|
||||
<!-- needs to match CEL -->
|
||||
<protobuf.version>4.28.1</protobuf.version>
|
||||
<geopackage.version>6.6.5</geopackage.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.onthegomap.planetiler.custommap;
|
|||
import com.google.api.expr.v1alpha1.Constant;
|
||||
import com.google.api.expr.v1alpha1.Decl;
|
||||
import com.google.api.expr.v1alpha1.Type;
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
import com.google.protobuf.NullValue;
|
||||
import com.onthegomap.planetiler.config.Arguments;
|
||||
import com.onthegomap.planetiler.config.PlanetilerConfig;
|
||||
|
@ -370,7 +371,7 @@ public class Contexts {
|
|||
public Object apply(String key) {
|
||||
if (key != null) {
|
||||
return switch (key) {
|
||||
case FEATURE_TAGS -> tagValueProducer.mapTags(feature);
|
||||
case FEATURE_TAGS -> mapWithDefault(tagValueProducer.mapTags(feature), NullValue.NULL_VALUE);
|
||||
case FEATURE_ID -> feature.id();
|
||||
case FEATURE_SOURCE -> feature.getSource();
|
||||
case FEATURE_SOURCE_LAYER -> wrapNullable(feature.getSourceLayer());
|
||||
|
@ -395,6 +396,20 @@ public class Contexts {
|
|||
}
|
||||
}
|
||||
|
||||
private static <K, V> Map<K, V> mapWithDefault(Map<K, V> map, Object nullValue) {
|
||||
return new ForwardingMap<>() {
|
||||
@Override
|
||||
protected Map<K, V> delegate() {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
return map.getOrDefault(key, (V) nullValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public FeaturePostMatch createPostMatchContext(List<String> matchKeys) {
|
||||
return new FeaturePostMatch(this, matchKeys);
|
||||
}
|
||||
|
|
|
@ -1287,4 +1287,38 @@ class ConfiguredFeatureTest {
|
|||
assertInstanceOf(Puntal.class, feature.getGeometry());
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWikidataParse() {
|
||||
var config = """
|
||||
sources:
|
||||
osm:
|
||||
type: osm
|
||||
url: geofabrik:rhode-island
|
||||
local_path: data/rhode-island.osm.pbf
|
||||
layers:
|
||||
- id: testLayer
|
||||
features:
|
||||
- source: osm
|
||||
geometry: point
|
||||
attributes:
|
||||
- key: wikidata
|
||||
value: "${feature.tags.wikidata != null ? int(feature.tags.wikidata.replace('Q', '')) : 0}"
|
||||
""";
|
||||
this.planetilerConfig = PlanetilerConfig.from(Arguments.of(Map.of()));
|
||||
testPoint(config, Map.of(
|
||||
"wikidata", "Q235"
|
||||
), feature -> {
|
||||
assertEquals(Map.of("wikidata", 235L), feature.getAttrsAtZoom(14));
|
||||
}, 1);
|
||||
testPoint(config, Map.of(
|
||||
"wikidata", "235"
|
||||
), feature -> {
|
||||
assertEquals(Map.of("wikidata", 235L), feature.getAttrsAtZoom(14));
|
||||
}, 1);
|
||||
testPoint(config, Map.of(
|
||||
), feature -> {
|
||||
assertEquals(Map.of("wikidata", 0L), feature.getAttrsAtZoom(14));
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ class ExpressionTests {
|
|||
"{'a': 2}.has('a', 1, 2)|true|boolean",
|
||||
"{'a': 2}.has('a', 3)|false|boolean",
|
||||
"{'a': 1}.has('b')|false|boolean",
|
||||
"int({'tags': {'wikidata': 'Q1'}}.tags.wikidata.replace('Q', ''))|1|long",
|
||||
|
||||
"coalesce({'a': 1}.get('a'), 2)|1|long",
|
||||
"coalesce({'a': 1}.get('b'), 2)|2|long",
|
||||
|
|
Ładowanie…
Reference in New Issue