Skip to content

Commit 91468b4

Browse files
committed
Use spark-testing-base - core tests green
- fixed weird init order in tests - all tests share same context now thanks to base - exclude scala-xml from tests
1 parent 725c9d5 commit 91468b4

23 files changed

+204
-127
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ lazy val core = project
7878
ExclusionRule(organization = "com.github.mpilquist")
7979
),
8080
scaffeine,
81-
scalatest,
81+
sparktestingbase excludeAll ExclusionRule("org.scala-lang.modules", "scala-xml_2.12"),
8282
`scala-logging`
8383
),
8484
libraryDependencies ++= {

core/src/main/scala/org/locationtech/rasterframes/expressions/aggregates/TileRasterizerAggregate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ object TileRasterizerAggregate {
137137

138138
destExtent.map { ext => c.copy(destinationExtent = ext) }
139139

140-
val aggs = tileCols.map(t => TileRasterizerAggregate(config, rf_crs(crsCol), extCol, rf_tile(t)).as(t.columnName))
140+
val aggs = tileCols.map(t => TileRasterizerAggregate(config, rf_tile(t), extCol, rf_crs(crsCol)).as(t.columnName))
141141

142142
val agg = df.select(aggs: _*)
143143

core/src/test/scala/org/locationtech/rasterframes/BaseUdtSpec.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import org.scalatest.Inspectors
2727

2828
class BaseUdtSpec extends TestEnvironment with TestData with Inspectors {
2929

30-
spark.version
31-
3230
it("should (de)serialize CRS") {
3331
val udt = new CrsUDT()
3432
val in = geotrellis.proj4.LatLng
@@ -37,6 +35,5 @@ class BaseUdtSpec extends TestEnvironment with TestData with Inspectors {
3735
out shouldBe in
3836
assert(out.isInstanceOf[LazyCRS])
3937
info(out.toString())
40-
4138
}
4239
}

core/src/test/scala/org/locationtech/rasterframes/CrsSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.locationtech.rasterframes.ref.RFRasterSource
2828
import org.locationtech.rasterframes.ref.RasterRef
2929

3030
class CrsSpec extends TestEnvironment with TestData with Inspectors {
31-
spark.version
3231
import spark.implicits._
3332

3433
describe("CrsUDT") {

core/src/test/scala/org/locationtech/rasterframes/GeometryFunctionsSpec.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ import org.locationtech.jts.geom.{Coordinate, GeometryFactory}
3232
* @since 12/16/17
3333
*/
3434
class GeometryFunctionsSpec extends TestEnvironment with TestData with StandardColumns {
35-
import spark.implicits._
36-
3735
describe("Vector geometry operations") {
38-
val rf = l8Sample(1).projectedRaster.toLayer(10, 10).withGeometry()
36+
lazy val rf = l8Sample(1).projectedRaster.toLayer(10, 10).withGeometry()
3937
it("should allow joining and filtering of tiles based on points") {
4038
import spark.implicits._
4139

@@ -136,6 +134,7 @@ class GeometryFunctionsSpec extends TestEnvironment with TestData with StandardC
136134
}
137135

138136
it("should rasterize geometry") {
137+
import spark.implicits._
139138
val rf = l8Sample(1).projectedRaster.toLayer.withGeometry()
140139
val df = GeomData.features.map(f => (
141140
f.geom.reproject(LatLng, rf.crs),

core/src/test/scala/org/locationtech/rasterframes/RasterFunctionsSpec.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
package org.locationtech.rasterframes
2323

2424
import geotrellis.raster._
25-
import geotrellis.raster.testkit.RasterMatchers
2625
import org.apache.spark.sql.functions._
2726
import org.locationtech.rasterframes.tiles.ProjectedRasterTile
2827

29-
class RasterFunctionsSpec extends TestEnvironment with RasterMatchers {
28+
class RasterFunctionsSpec extends TestEnvironment {
3029
import TestData._
3130
import spark.implicits._
3231

core/src/test/scala/org/locationtech/rasterframes/RasterJoinSpec.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ package org.locationtech.rasterframes
2323

2424
import geotrellis.proj4.CRS
2525
import geotrellis.raster.resample._
26-
import geotrellis.raster.testkit.RasterMatchers
2726
import geotrellis.raster.{Dimensions, IntConstantNoDataCellType, Raster, Tile}
2827
import geotrellis.vector.Extent
2928
import org.apache.spark.SparkConf
@@ -32,18 +31,18 @@ import org.locationtech.rasterframes.expressions.aggregates.TileRasterizerAggreg
3231
import org.locationtech.rasterframes.expressions.aggregates.TileRasterizerAggregate.ProjectedRasterDefinition
3332

3433

35-
class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
36-
import spark.implicits._
34+
class RasterJoinSpec extends TestEnvironment with TestData {
3735
describe("Raster join between two DataFrames") {
3836
val b4nativeTif = readSingleband("L8-B4-Elkton-VA.tiff")
3937
// Same data, reprojected to EPSG:4326
4038
val b4warpedTif = readSingleband("L8-B4-Elkton-VA-4326.tiff")
4139

42-
val b4nativeRf = b4nativeTif.toDF(Dimensions(10, 10))
43-
val b4warpedRf = b4warpedTif.toDF(Dimensions(10, 10))
40+
lazy val b4nativeRf = b4nativeTif.toDF(Dimensions(10, 10))
41+
lazy val b4warpedRf = b4warpedTif.toDF(Dimensions(10, 10))
4442
.withColumnRenamed("tile", "tile2")
4543

4644
it("should join the same scene correctly") {
45+
import spark.implicits._
4746
val b4nativeRfPrime = b4nativeTif.toDF(Dimensions(10, 10))
4847
.withColumnRenamed("tile", "tile2")
4948
val joined = b4nativeRf.rasterJoin(b4nativeRfPrime.hint("broadcast"))
@@ -59,6 +58,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
5958
}
6059

6160
it("should join same scene in different tile sizes"){
61+
import spark.implicits._
6262
val r1prime = b4nativeTif.toDF(Dimensions(25, 25)).withColumnRenamed("tile", "tile2")
6363
r1prime.select(rf_dimensions($"tile2").getField("rows")).as[Int].first() should be (25)
6464
val joined = b4nativeRf.rasterJoin(r1prime)
@@ -75,6 +75,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
7575
}
7676

7777
it("should join same scene in two projections, same tile size") {
78+
import spark.implicits._
7879
val srcExtent = b4nativeTif.extent
7980
// b4warpedRf source data is gdal warped b4nativeRf data; join them together.
8081
val joined = b4nativeRf.rasterJoin(b4warpedRf)
@@ -112,6 +113,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
112113
}
113114

114115
it("should join multiple RHS tile columns"){
116+
import spark.implicits._
115117
// join multiple native CRS bands to the EPSG 4326 RF
116118

117119
val multibandRf = b4nativeRf
@@ -126,6 +128,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
126128
}
127129

128130
it("should join with heterogeneous LHS CRS and coverages"){
131+
import spark.implicits._
129132

130133
val df17 = readSingleband("m_3607824_se_17_1_20160620_subset.tif")
131134
.toDF(Dimensions(50, 50))
@@ -165,6 +168,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
165168
}
166169

167170
it("should handle proj_raster types") {
171+
import spark.implicits._
168172
val df1 = Seq(Option(one)).toDF("one")
169173
val df2 = Seq(Option(two)).toDF("two")
170174
noException shouldBe thrownBy {
@@ -174,6 +178,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
174178
}
175179

176180
it("should raster join multiple times on projected raster"){
181+
import spark.implicits._
177182
val df0 = Seq(Option(one)).toDF("proj_raster")
178183
val result = df0.select($"proj_raster" as "t1")
179184
.rasterJoin(df0.select($"proj_raster" as "t2"))
@@ -184,6 +189,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
184189
}
185190

186191
it("should honor resampling options") {
192+
import spark.implicits._
187193
// test case. replicate existing test condition and check that resampling option results in different output
188194
val filterExpr = st_intersects(rf_geometry($"tile"), st_point(704940.0, 4251130.0))
189195
val result = b4nativeRf.rasterJoin(b4warpedRf.withColumnRenamed("tile2", "nearest"), NearestNeighbor)
@@ -200,6 +206,7 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
200206
// Failed to execute user defined function(package$$$Lambda$4417/0x00000008019e2840: (struct<xmax:double,xmin:double,ymax:double,ymin:double>, string, array<struct<cellType:string,cols:int,rows:int,cells:binary,ref:struct<source:struct<raster_source_kryo:binary>,bandIndex:int,subextent:struct<xmin:double,ymin:double,xmax:double,ymax:double>,subgrid:struct<colMin:int,rowMin:int,colMax:int,rowMax:int>>>>, array<struct<xmax:double,xmin:double,ymax:double,ymin:double>>, array<string>, struct<cols:int,rows:int>, string) => struct<cellType:string,cols:int,rows:int,cells:binary,ref:struct<source:struct<raster_source_kryo:binary>,bandIndex:int,subextent:struct<xmin:double,ymin:double,xmax:double,ymax:double>,subgrid:struct<colMin:int,rowMin:int,colMax:int,rowMax:int>>>)
201207

202208
it("should raster join with null left head") {
209+
import spark.implicits._
203210
// https://github.com/locationtech/rasterframes/issues/462
204211
val prt = TestData.projectedRasterTile(
205212
10, 10, 1,
@@ -264,5 +271,5 @@ class RasterJoinSpec extends TestEnvironment with TestData with RasterMatchers {
264271

265272
}
266273

267-
override def additionalConf: SparkConf = super.additionalConf.set("spark.sql.codegen.comments", "true")
274+
override def additionalConf(conf: SparkConf) = conf.set("spark.sql.codegen.comments", "true")
268275
}

core/src/test/scala/org/locationtech/rasterframes/SpatialKeySpec.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ import org.locationtech.geomesa.curve.Z2SFC
3131
* @since 12/15/17
3232
*/
3333
class SpatialKeySpec extends TestEnvironment with TestData {
34-
assert(!spark.sparkContext.isStopped)
35-
36-
import spark.implicits._
37-
3834
describe("Spatial key conversions") {
3935
val raster = sampleGeoTiff.projectedRaster
4036
// Create a raster frame with a single row
41-
val rf = raster.toLayer(raster.tile.cols, raster.tile.rows)
37+
lazy val rf = raster.toLayer(raster.tile.cols, raster.tile.rows)
4238

4339
it("should add an extent column") {
4440
val expected = raster.extent.toPolygon()
@@ -53,12 +49,14 @@ class SpatialKeySpec extends TestEnvironment with TestData {
5349
}
5450

5551
it("should add a center lat/lng value") {
52+
import spark.implicits._
5653
val expected = raster.extent.center.reproject(raster.crs, LatLng)
5754
val result = rf.withCenterLatLng().select($"center".as[(Double, Double)]).first
5855
assert( Point(result._1, result._2) === expected)
5956
}
6057

6158
it("should add a z-index value") {
59+
import spark.implicits._
6260
val center = raster.extent.center.reproject(raster.crs, LatLng)
6361
val expected = Z2SFC.index(center.x, center.y)
6462
val result = rf.withSpatialIndex().select($"spatial_index".as[Long]).first

core/src/test/scala/org/locationtech/rasterframes/StandardEncodersSpec.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import org.scalatest.Inspectors
3737
class StandardEncodersSpec extends TestEnvironment with TestData with Inspectors {
3838

3939
it("Dimensions encoder") {
40-
spark.version
4140
import spark.implicits._
4241
val data = Dimensions[Int](256, 256)
4342
val df = List(data).toDF()
@@ -47,7 +46,6 @@ class StandardEncodersSpec extends TestEnvironment with TestData with Inspectors
4746
}
4847

4948
it("TileDataContext encoder") {
50-
spark.version
5149
import spark.implicits._
5250
val data = TileDataContext(IntCellType, Dimensions[Int](256, 256))
5351
val df = List(data).toDF()
@@ -57,7 +55,6 @@ class StandardEncodersSpec extends TestEnvironment with TestData with Inspectors
5755
}
5856

5957
it("ProjectedExtent encoder") {
60-
spark.version
6158
import spark.implicits._
6259
val data = ProjectedExtent(Extent(0, 0, 1, 1), LatLng)
6360
val df = List(data).toDF()
@@ -68,7 +65,6 @@ class StandardEncodersSpec extends TestEnvironment with TestData with Inspectors
6865
}
6966

7067
it("TileLayerMetadata encoder"){
71-
spark.version
7268
import spark.implicits._
7369
val data = TileLayerMetadata(
7470
IntCellType,

core/src/test/scala/org/locationtech/rasterframes/TestEnvironment.scala

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
*/
2121
package org.locationtech.rasterframes
2222

23-
import java.nio.file.{Files, Path}
23+
import com.holdenkarau.spark.testing.DataFrameSuiteBase
2424

25+
import java.nio.file.{Files, Path}
2526
import com.typesafe.scalalogging.Logger
2627
import geotrellis.raster.Tile
2728
import geotrellis.raster.render.{ColorMap, ColorRamps}
@@ -39,11 +40,10 @@ import org.scalactic.Tolerance
3940
import org.scalatest._
4041
import org.scalatest.funspec.AnyFunSpec
4142
import org.scalatest.matchers.should.Matchers
42-
4343
import org.scalatest.matchers.{MatchResult, Matcher}
4444
import org.slf4j.LoggerFactory
4545

46-
trait TestEnvironment extends AnyFunSpec with Matchers with Inspectors with Tolerance with RasterMatchers {
46+
trait TestEnvironment extends AnyFunSpec with DataFrameSuiteBase with Matchers with RasterMatchers with Inspectors with Tolerance {
4747
@transient protected lazy val logger = Logger(LoggerFactory.getLogger(getClass.getName))
4848

4949

@@ -56,22 +56,29 @@ trait TestEnvironment extends AnyFunSpec with Matchers with Inspectors with Tole
5656
// allow 2 retries, should stabilize CI builds. https://spark.apache.org/docs/2.4.7/submitting-applications.html#master-urls
5757
def sparkMaster: String = "local[*, 2]"
5858

59-
def additionalConf: SparkConf =
60-
new SparkConf(false)
61-
.set("spark.driver.port", "0")
62-
.set("spark.hostPort", "0")
63-
.set("spark.ui.enabled", "false")
64-
65-
implicit val spark: SparkSession =
66-
SparkSession
67-
.builder
68-
.master(sparkMaster)
69-
.withKryoSerialization
70-
.config(additionalConf)
71-
.getOrCreate()
72-
.withRasterFrames
73-
74-
implicit def sc: SparkContext = spark.sparkContext
59+
protected def additionalConf(conf: SparkConf): SparkConf = conf
60+
61+
override def conf: SparkConf = {
62+
val base = new SparkConf().
63+
setAppName("RasterFrames Test").
64+
setMaster(sparkMaster).
65+
set("spark.serializer", "org.apache.spark.serializer.KryoSerializer").
66+
set("spark.kryo.registrator", "org.locationtech.rasterframes.util.RFKryoRegistrator").
67+
set("spark.ui.enabled", "false").
68+
set("spark.driver.port", "0").
69+
set("spark.hostPort", "0").
70+
set("spark.ui.enabled", "true")
71+
additionalConf(base)
72+
}
73+
74+
override def setup(sc: SparkContext): Unit = {
75+
sc.setCheckpointDir(com.holdenkarau.spark.testing.Utils.createTempDir().toPath().toString)
76+
sc.setLogLevel("ERROR")
77+
org.locationtech.rasterframes.initRF(sqlContext)
78+
}
79+
80+
implicit def sparkSession: SparkSession = spark
81+
implicit def sparkContext: SparkContext = spark.sparkContext
7582

7683
lazy val sql: String => DataFrame = spark.sql
7784

0 commit comments

Comments
 (0)