Skip to content

Commit 007e0b6

Browse files
committed
Cleanup datasource project
1 parent e355083 commit 007e0b6

File tree

8 files changed

+27
-92
lines changed

8 files changed

+27
-92
lines changed

bench/src/main/scala/org/locationtech/rasterframes/bench/TileCellScanBench.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import java.util.concurrent.TimeUnit
2626
import geotrellis.raster.Dimensions
2727
import org.apache.spark.sql.catalyst.InternalRow
2828
import org.apache.spark.sql.rf.TileUDT
29-
import org.locationtech.rasterframes.tiles.InternalRowTile
3029
import org.openjdk.jmh.annotations._
3130

3231
@BenchmarkMode(Array(Mode.AverageTime))
@@ -62,15 +61,4 @@ class TileCellScanBench extends SparkEnv {
6261
tile.getDouble(cols/2, rows/2) +
6362
tile.getDouble(0, 0)
6463
}
65-
66-
@Benchmark
67-
def internalRowRead(): Double = {
68-
val tile = new InternalRowTile(tileRow)
69-
val cols = tile.cols
70-
val rows = tile.rows
71-
tile.getDouble(cols - 1, rows - 1) +
72-
tile.getDouble(cols/2, rows/2) +
73-
tile.getDouble(0, 0)
74-
}
7564
}
76-

core/src/main/scala/org/locationtech/rasterframes/tiles/ProjectedRasterTile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ object ProjectedRasterTile {
5959
Some((prt.tile, prt.extent, prt.crs))
6060

6161
implicit lazy val projectedRasterTileEncoder: ExpressionEncoder[ProjectedRasterTile] = ExpressionEncoder[ProjectedRasterTile]()
62-
}
62+
}

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

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

2424
import geotrellis.raster
2525
import geotrellis.raster.{CellType, Dimensions, NoNoData, Tile}
26-
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
2726
import org.apache.spark.sql.types.StringType
2827
import org.locationtech.rasterframes.tiles.ShowableTile
2928
import org.scalatest.Inspectors
@@ -37,7 +36,6 @@ class TileUDTSpec extends TestEnvironment with TestData with Inspectors {
3736
import TestData.randomTile
3837

3938
spark.version
40-
val tileEncoder: ExpressionEncoder[Tile] = ExpressionEncoder()
4139

4240
describe("TileUDT") {
4341
val tileSizes = Seq(2, 7, 64, 128, 511)
@@ -97,7 +95,7 @@ class TileUDTSpec extends TestEnvironment with TestData with Inspectors {
9795

9896
if (rfConfig.getBoolean("showable-tiles"))
9997
forEveryConfig { tile =>
100-
val stringified = Seq(Option(tile)).toDF("tile").select($"tile".cast(StringType)).as[String].first()
98+
val stringified = Seq(tile).toDF("tile").select($"tile".cast(StringType)).as[String].first()
10199
stringified should be(ShowableTile.show(tile))
102100

103101
if(!tile.cellType.isInstanceOf[NoNoData]) {

datasource/src/main/scala/org/locationtech/rasterframes/datasource/geotiff/GeoTiffRelation.scala

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@
2121

2222
package org.locationtech.rasterframes.datasource.geotiff
2323

24-
import java.net.URI
25-
import com.typesafe.scalalogging.Logger
2624
import geotrellis.layer._
2725
import geotrellis.spark._
2826
import geotrellis.store.hadoop.util.HdfsRangeReader
2927
import org.apache.hadoop.fs.Path
3028
import org.apache.spark.rdd.RDD
31-
import org.apache.spark.sql.catalyst.encoders.{ExpressionEncoder, RowEncoder}
29+
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
3230
import org.apache.spark.sql.rf.TileUDT
3331
import org.apache.spark.sql.sources._
3432
import org.apache.spark.sql.types._
3533
import org.apache.spark.sql.{Row, SQLContext}
36-
import org.locationtech.rasterframes._
3734
import org.locationtech.rasterframes.util._
3835
import org.slf4j.LoggerFactory
3936
import JsonCodecs._
4037
import geotrellis.raster.CellGrid
4138
import geotrellis.spark.store.hadoop.{HadoopGeoTiffRDD, HadoopGeoTiffReader}
42-
import org.locationtech.rasterframes.encoders.StandardEncoders
39+
import org.locationtech.rasterframes._
40+
import org.locationtech.rasterframes.encoders.syntax._
41+
42+
import java.net.URI
43+
import com.typesafe.scalalogging.Logger
4344

4445
/**
4546
* Spark SQL data source over a single GeoTiff file. Works best with CoG compliant ones.
@@ -71,11 +72,9 @@ case class GeoTiffRelation(sqlContext: SQLContext, uri: URI) extends BaseRelatio
7172

7273
StructType(Seq(
7374
StructField(SPATIAL_KEY_COLUMN.columnName, skSchema, nullable = false, skMetadata),
74-
StructField(EXTENT_COLUMN.columnName, StandardEncoders.extentEncoder.schema, nullable = true),
75-
StructField(CRS_COLUMN.columnName, CrsType, nullable = true),
76-
StructField(METADATA_COLUMN.columnName,
77-
DataTypes.createMapType(StringType, StringType, false)
78-
)
75+
StructField(EXTENT_COLUMN.columnName, extentEncoder.schema, nullable = true),
76+
StructField(CRS_COLUMN.columnName, crsUDT, nullable = true),
77+
StructField(METADATA_COLUMN.columnName, DataTypes.createMapType(StringType, StringType, false))
7978
) ++ tileCols)
8079
}
8180

@@ -90,14 +89,7 @@ case class GeoTiffRelation(sqlContext: SQLContext, uri: URI) extends BaseRelatio
9089
val trans = tlm.mapTransform
9190
val metadata = info.tags.headTags
9291

93-
val encodedCRS =
94-
RowEncoder(StandardEncoders.crsSparkEncoder.schema)
95-
.resolveAndBind()
96-
.createDeserializer()(
97-
StandardEncoders
98-
.crsSparkEncoder
99-
.createSerializer()(tlm.crs)
100-
)
92+
val encodedCRS = tlm.crs.toRow
10193

10294
if(info.segmentLayout.isTiled) {
10395
// TODO: Figure out how to do tile filtering via the range reader.
@@ -108,22 +100,8 @@ case class GeoTiffRelation(sqlContext: SQLContext, uri: URI) extends BaseRelatio
108100
// transform result because the layout is directly from the TIFF
109101
val gb = trans.extentToBounds(pe.extent)
110102
val entries = columnIndexes.map {
111-
case 0 =>
112-
RowEncoder(StandardEncoders.spatialKeyEncoder.schema)
113-
.resolveAndBind()
114-
.createDeserializer()(
115-
StandardEncoders
116-
.spatialKeyEncoder
117-
.createSerializer()(SpatialKey(gb.colMin, gb.rowMin))
118-
)
119-
case 1 =>
120-
RowEncoder(StandardEncoders.extentEncoder.schema)
121-
.resolveAndBind()
122-
.createDeserializer()(
123-
StandardEncoders
124-
.extentEncoder
125-
.createSerializer()(pe.extent)
126-
)
103+
case 0 => SpatialKey(gb.colMin, gb.rowMin).toRow
104+
case 1 => pe.extent.toRow
127105
case 2 => encodedCRS
128106
case 3 => metadata
129107
case n => tiles.band(n - 4)
@@ -147,14 +125,7 @@ case class GeoTiffRelation(sqlContext: SQLContext, uri: URI) extends BaseRelatio
147125
.map { case (sk, tiles) =>
148126
val entries = columnIndexes.map {
149127
case 0 => sk
150-
case 1 =>
151-
RowEncoder(StandardEncoders.extentEncoder.schema)
152-
.resolveAndBind()
153-
.createDeserializer()(
154-
StandardEncoders
155-
.extentEncoder
156-
.createSerializer()(trans.keyToExtent(sk))
157-
)
128+
case 1 => trans.keyToExtent(sk).toRow
158129
case 2 => encodedCRS
159130
case 3 => metadata
160131
case n => tiles.band(n - 4)

datasource/src/main/scala/org/locationtech/rasterframes/datasource/geotrellis/Layer.scala

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

2222
package org.locationtech.rasterframes.datasource.geotrellis
2323

24+
import org.locationtech.rasterframes._
25+
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
26+
27+
import geotrellis.store.LayerId
2428
import frameless.TypedEncoder
2529

2630
import java.net.URI
27-
import org.locationtech.rasterframes.encoders.typedExpressionEncoder
28-
import geotrellis.store.LayerId
29-
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
3031

3132
/**
3233
* /** Connector between a GT `LayerId` and the path in which it lives. */
@@ -36,11 +37,9 @@ import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
3637
case class Layer(base: URI, id: LayerId)
3738

3839
object Layer {
39-
import org.locationtech.rasterframes.encoders.StandardEncoders._
40-
4140
def apply(base: URI, name: String, zoom: Int) = new Layer(base, LayerId(name, zoom))
4241

43-
implicit def typedLayerEncoder: TypedEncoder[Layer] = TypedEncoder.usingDerivation
42+
implicit val typedLayerEncoder: TypedEncoder[Layer] = TypedEncoder.usingDerivation
4443

45-
implicit def layerEncoder: ExpressionEncoder[Layer] = typedExpressionEncoder[Layer]
44+
implicit val layerEncoder: ExpressionEncoder[Layer] = typedExpressionEncoder[Layer]
4645
}

datasource/src/main/scala/org/locationtech/rasterframes/datasource/raster/RasterSourceRelation.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ case class RasterSourceRelation(
8282
sqlContext.sparkSession.sessionState.conf.numShufflePartitions
8383

8484
override def schema: StructType = {
85-
val tileSchema = ProjectedRasterTile.prtEncoder.schema
85+
val tileSchema = ProjectedRasterTile.projectedRasterTileEncoder.schema
8686
val paths = for {
8787
pathCol <- pathColNames
8888
} yield StructField(pathCol, StringType, false)

datasource/src/test/scala/examples/ExplodeWithLocation.scala

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ package examples
2424
import geotrellis.raster._
2525
import geotrellis.vector.Extent
2626
import org.apache.spark.sql._
27-
import org.apache.spark.sql.catalyst.encoders.RowEncoder
2827
import org.apache.spark.sql.functions._
2928
import org.locationtech.rasterframes._
29+
import org.locationtech.rasterframes.encoders.syntax._
3030
import org.locationtech.rasterframes.datasource.raster._
31-
import org.locationtech.rasterframes.encoders.CatalystSerializer._
32-
import org.locationtech.rasterframes.encoders.StandardEncoders
3331

3432
object ExplodeWithLocation extends App {
3533

@@ -44,20 +42,8 @@ object ExplodeWithLocation extends App {
4442
val rf = spark.read.raster.from(example).withTileDimensions(16, 16).load()
4543

4644
val grid2map = udf((encExtent: Row, encDims: Row, colIdx: Int, rowIdx: Int) => {
47-
val extent =
48-
extentEncoder
49-
.resolveAndBind()
50-
.createDeserializer()(
51-
RowEncoder(extentEncoder.schema)
52-
.createSerializer()(encExtent)
53-
)
54-
val dims =
55-
dimensionsEncoder
56-
.resolveAndBind()
57-
.createDeserializer()(
58-
RowEncoder(dimensionsEncoder.schema)
59-
.createSerializer()(encDims)
60-
)
45+
val extent = encExtent.as[Extent]
46+
val dims = encDims.as[Dimensions[Int]]
6147
GridExtent(extent, dims.cols, dims.rows).gridToMap(colIdx, rowIdx)
6248
})
6349

datasource/src/test/scala/examples/ValueAtPoint.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ package examples
2424
import org.apache.spark.sql._
2525
import org.apache.spark.sql.functions._
2626
import org.locationtech.rasterframes._
27+
import org.locationtech.rasterframes.encoders.syntax._
2728
import org.locationtech.rasterframes.datasource.raster._
28-
import org.locationtech.rasterframes.encoders.CatalystSerializer._
2929
import geotrellis.raster._
3030
import geotrellis.vector.Extent
31-
import org.apache.spark.sql.catalyst.encoders.RowEncoder
3231
import org.locationtech.jts.geom.Point
3332

3433
object ValueAtPoint extends App {
@@ -45,13 +44,7 @@ object ValueAtPoint extends App {
4544
val point = st_makePoint(766770.000, 3883995.000)
4645

4746
val rf_value_at_point = udf((extentEnc: Row, tile: Tile, point: Point) => {
48-
val extent =
49-
extentEncoder
50-
.resolveAndBind()
51-
.createDeserializer()(
52-
RowEncoder(extentEncoder.schema)
53-
.createSerializer()(extentEnc)
54-
)
47+
val extent = extentEnc.as[Extent]
5548
Raster(tile, extent).getDoubleValueAtPoint(point)
5649
})
5750

0 commit comments

Comments
 (0)