Skip to content

Commit 6e78377

Browse files
authored
Merge pull request #345 from s22s/fix/267
Fixed Exception swallowing in RasterSource.
2 parents d183c81 + 19b9573 commit 6e78377

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

core/src/main/scala/org/locationtech/rasterframes/expressions/generators/RasterSourceToRasterRefs.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
package org.locationtech.rasterframes.expressions.generators
2323

24-
import com.typesafe.scalalogging.LazyLogging
2524
import geotrellis.raster.GridBounds
2625
import geotrellis.vector.Extent
2726
import org.apache.spark.sql.catalyst.InternalRow
@@ -45,7 +44,7 @@ import scala.util.control.NonFatal
4544
* @since 9/6/18
4645
*/
4746
case class RasterSourceToRasterRefs(children: Seq[Expression], bandIndexes: Seq[Int], subtileDims: Option[TileDimensions] = None) extends Expression
48-
with Generator with CodegenFallback with ExpectsInputTypes with LazyLogging {
47+
with Generator with CodegenFallback with ExpectsInputTypes {
4948

5049
override def inputTypes: Seq[DataType] = Seq.fill(children.size)(RasterSourceType)
5150
override def nodeName: String = "rf_raster_source_to_raster_ref"
@@ -77,9 +76,10 @@ case class RasterSourceToRasterRefs(children: Seq[Expression], bandIndexes: Seq[
7776
}
7877
catch {
7978
case NonFatal(ex)
80-
val payload = Try(children.map(c => RasterSourceType.deserialize(c.eval(input)))).toOption.toSeq.flatten
81-
logger.error("Error fetching data for one of: " + payload.mkString(", "), ex)
82-
Traversable.empty
79+
val description = "Error fetching data for one of: " +
80+
Try(children.map(c => RasterSourceType.deserialize(c.eval(input))))
81+
.toOption.toSeq.flatten.mkString(", ")
82+
throw new java.lang.IllegalArgumentException(description, ex)
8383
}
8484
}
8585
}

core/src/test/scala/org/locationtech/rasterframes/ref/RasterRefSpec.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
package org.locationtech.rasterframes.ref
2323

24+
import java.net.URI
25+
2426
import geotrellis.raster.{ByteConstantNoDataCellType, Tile}
2527
import geotrellis.vector.Extent
28+
import org.apache.spark.SparkException
2629
import org.apache.spark.sql.Encoders
2730
import org.locationtech.rasterframes.{TestEnvironment, _}
2831
import org.locationtech.rasterframes.expressions.accessors._
@@ -205,6 +208,16 @@ class RasterRefSpec extends TestEnvironment with TestData {
205208
r.rows should be <= NOMINAL_TILE_SIZE
206209
}
207210
}
211+
it("should throw exception on invalid URI") {
212+
val src = RasterSource(URI.create("http://foo/bar"))
213+
import spark.implicits._
214+
val df = Seq(src).toDF("src")
215+
val refs = df.select(RasterSourceToRasterRefs($"src") as "proj_raster")
216+
logger.warn(Console.REVERSED + "Upcoming 'java.lang.IllegalArgumentException' expected in logs." + Console.RESET)
217+
assertThrows[SparkException] {
218+
refs.first()
219+
}
220+
}
208221
}
209222

210223
describe("RealizeTile") {

docs/src/main/paradox/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
### 0.8.2
66

7+
* Fixed issue with `RasterSourceDataSource` swallowing exceptions. ([#267](https://github.com/locationtech/rasterframes/issues/267))
78
* Fixed SparkML memory pressure issue caused by unnecessary reevaluation, overallocation, and primitive boxing. ([#343](https://github.com/locationtech/rasterframes/issues/343))
89
* Fixed Parquet serialization issue with `RasterRef`s ([#338](https://github.com/locationtech/rasterframes/issues/338))
910
* Fixed `TileExploder`, `rf_agg_local_mean` and `TileColumnSupport` to support `proj_raster` struct ([#287](https://github.com/locationtech/rasterframes/issues/287), [#163](https://github.com/locationtech/rasterframes/issues/163), [#333](https://github.com/locationtech/rasterframes/issues/333)).
1011
* Various documentation improvements.
12+
* _Breaking_ (potentially): Synchronized parameter naming in Python and Scala for `spark.read.raster` ([#329](https://github.com/locationtech/rasterframes/pull/329)).
13+
1114

1215
### 0.8.1
1316

pyrasterframes/src/main/python/tests/RasterSourceTest.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,26 @@ def test_list_of_list_of_str(self):
124124
self.assertTrue(len(df.columns) == 4) # 2 cols of uris plus 2 cols of proj_rasters
125125
self.assertEqual(sorted(df.columns), sorted(['proj_raster_0_path', 'proj_raster_1_path',
126126
'proj_raster_0', 'proj_raster_1']))
127-
uri_df = df.select('proj_raster_0_path', 'proj_raster_1_path').distinct().collect()
128-
uri_list = [list(r.asDict().values()) for r in uri_df]
129-
self.assertTrue(lol[0] in uri_list)
130-
self.assertTrue(lol[1] in uri_list)
131-
self.assertTrue(lol[2] in uri_list)
127+
uri_df = df.select('proj_raster_0_path', 'proj_raster_1_path').distinct()
128+
129+
# check that various uri's are in the dataframe
130+
self.assertEqual(
131+
uri_df.filter(col('proj_raster_0_path') == lit(self.path(1, 1))).count(),
132+
1)
133+
134+
self.assertEqual(
135+
uri_df \
136+
.filter(col('proj_raster_0_path') == lit(self.path(1, 1))) \
137+
.filter(col('proj_raster_1_path') == lit(self.path(1, 2))) \
138+
.count(),
139+
1)
140+
141+
self.assertEqual(
142+
uri_df \
143+
.filter(col('proj_raster_0_path') == lit(self.path(3, 1))) \
144+
.filter(col('proj_raster_1_path') == lit(self.path(3, 2))) \
145+
.count(),
146+
1)
132147

133148
def test_schemeless_string(self):
134149
import os.path

0 commit comments

Comments
 (0)