Skip to content

Commit 3a368ca

Browse files
authored
GeoTrellisPath.parse should preserve unrecognized uri parameters (#3529)
* GeoTrellisPath.parse should preserve unrecognized uri parameters * Adjust tests * CHANGELOG.md update
1 parent 133a2d0 commit 3a368ca

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Fix FileRangeReaderProvider parsing URI in windows [#3507](https://github.com/locationtech/geotrellis/pull/3507)
1414
- Regrid: force crop to avoid going out of memory [#3518](https://github.com/locationtech/geotrellis/pull/3518)
1515
- Fix rounding errors/numerical instability in GridExtent and LayoutTileSource [#3520](https://github.com/locationtech/geotrellis/pull/3520)
16+
- GeoTrellisPath.parse should preserve unrecognized uri parameters [#3529](https://github.com/locationtech/geotrellis/pull/3529)
1617

1718
## [3.7.0] - 2023-02-26
1819

store/src/main/scala/geotrellis/store/GeoTrellisPath.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ object GeoTrellisPath {
5555
implicit def toGeoTrellisDataPath(path: String): GeoTrellisPath = parse(path)
5656

5757
def parseOption(path: String): Option[GeoTrellisPath] = {
58-
val layerNameParam: String = "layer"
59-
val zoomLevelParam: String = "zoom"
60-
val bandCountParam: String = "band_count"
58+
val layerNameParam = "layer"
59+
val zoomLevelParam = "zoom"
60+
val bandCountParam = "band_count"
6161

6262
val uri = UrlWithAuthority.parseOption(path).fold(Url.parse(path))(identity)
6363
val queryString = uri.query
@@ -70,13 +70,18 @@ object GeoTrellisPath {
7070
case _ => ""
7171
}
7272

73-
s"${scheme.split("\\+").last}://$authority${uri.path}".some
73+
val queryStringFiltered = {
74+
val filtered = queryString.removeAll(layerNameParam, zoomLevelParam, bandCountParam)
75+
if(filtered.isEmpty) "" else s"?${filtered.toString()}"
76+
}
77+
78+
s"${scheme.split("\\+").last}://$authority${uri.path}$queryStringFiltered".trim.some
7479
}
7580

7681
catalogPath.fold(Option.empty[GeoTrellisPath]) { catalogPath =>
77-
val maybeLayerName: Option[String] = queryString.param(layerNameParam)
78-
val maybeZoomLevel: Option[Int] = queryString.param(zoomLevelParam).map(_.toInt)
79-
val bandCount: Option[Int] = queryString.param(bandCountParam).map(_.toInt)
82+
val maybeLayerName = queryString.param(layerNameParam)
83+
val maybeZoomLevel = queryString.param(zoomLevelParam).map(_.toInt)
84+
val bandCount = queryString.param(bandCountParam).map(_.toInt)
8085

8186
(maybeLayerName, maybeZoomLevel) match {
8287
case (Some(layerName), Some(zoomLevel)) =>

store/src/test/scala/geotrellis/store/GeoTrellisPathSpec.scala

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class GeoTrellisPathSpec extends AnyFunSpec {
2323

2424
it("should fail to parse without a layer") {
2525
val path = GeoTrellisPath.parseOption("file:///foo/bar?zoom=1")
26-
assert(path == None)
26+
assert(path.isEmpty)
2727
}
2828

2929
it("should fail to parse without a zoom") {
3030
val path = GeoTrellisPath.parseOption("file:///foo/bar?layer=baz")
31-
assert(path == None)
31+
assert(path.isEmpty)
3232
}
3333

3434
it("should parse a local absolute file path without scheme") {
@@ -59,7 +59,7 @@ class GeoTrellisPathSpec extends AnyFunSpec {
5959
val path = GeoTrellisPath.parse("file:///foo/bar?layer=baz&band_count=1&zoom=10")
6060
assert(path.layerName == "baz")
6161
assert(path.zoomLevel == 10)
62-
assert(path.bandCount == Some(1))
62+
assert(path.bandCount.contains(1))
6363
}
6464

6565
it("should parse hdfs scheme") {
@@ -74,6 +74,20 @@ class GeoTrellisPathSpec extends AnyFunSpec {
7474
assert(path.layerName == "foo")
7575
}
7676

77+
it("should parse hbase scheme") {
78+
val path = GeoTrellisPath.parse("hbase://zookeeper:2181?master=master_host&attributes=attributes_table&layers=layers_table&layer=foo&zoom=1")
79+
assert(path.value == "hbase://zookeeper:2181?master=master_host&attributes=attributes_table&layers=layers_table")
80+
assert(path.layerName == "foo")
81+
assert(path.zoomLevel == 1)
82+
}
83+
84+
it("should parse accumulo scheme") {
85+
val path = GeoTrellisPath.parse("accumulo://root:@localhost/fake?attributes=attributes&layers=tiles&layer=foo&zoom=1")
86+
assert(path.value == "accumulo://root:@localhost/fake?attributes=attributes&layers=tiles")
87+
assert(path.layerName == "foo")
88+
assert(path.zoomLevel == 1)
89+
}
90+
7791
it("should parse absolute file scheme with gt+ prefix") {
7892
val path = GeoTrellisPath.parse("gt+file:///absolute/path?layer=foo&zoom=1")
7993
assert(path.value == "file:///absolute/path")
@@ -92,9 +106,9 @@ class GeoTrellisPathSpec extends AnyFunSpec {
92106
assert(path.layerName == "foo")
93107
}
94108

95-
it("should ignore invalid parameters") {
109+
it("should not ignore invalid parameters") {
96110
val path = GeoTrellisPath.parse("file:///foo/bar?layer=baz&zoom=1&invalid=not&nope=1")
97-
assert(path == GeoTrellisPath("file:///foo/bar", "baz", 1, None))
111+
assert(path == GeoTrellisPath("file:///foo/bar?invalid=not&nope=1", "baz", 1, None))
98112
}
99113
}
100114
}

0 commit comments

Comments
 (0)