Skip to content

Commit 927ef90

Browse files
committed
Fixes #67
Signed-off-by: Simeon H.K. Fitch <[email protected]>
1 parent 00319fc commit 927ef90

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

core/src/main/scala/astraea/spark/rasterframes/extensions/ContextRDDMethods.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ abstract class SpatialContextRDDMethods[T <: CellGrid](implicit spark: SparkSess
3939
def toRF(implicit converter: PairRDDConverter[SpatialKey, T]): RasterFrame = toRF(TILE_COLUMN.columnName)
4040

4141
def toRF(tileColumnName: String)(implicit converter: PairRDDConverter[SpatialKey, T]): RasterFrame = {
42-
val df = self.toDataFrame
43-
df.setSpatialColumnRole(SPATIAL_KEY_COLUMN, self.metadata)
42+
val df = self.toDataFrame.setSpatialColumnRole(SPATIAL_KEY_COLUMN, self.metadata)
43+
val defName = TILE_COLUMN.columnName
44+
df.mapWhen(_ tileColumnName != defName, _.withColumnRenamed(defName, tileColumnName))
4445
.certify
4546
}
4647
}
@@ -56,9 +57,11 @@ abstract class SpatioTemporalContextRDDMethods[T <: CellGrid](
5657
def toRF(implicit converter: PairRDDConverter[SpaceTimeKey, T]): RasterFrame = toRF(TILE_COLUMN.columnName)
5758

5859
def toRF(tileColumnName: String)(implicit converter: PairRDDConverter[SpaceTimeKey, T]): RasterFrame = {
59-
self.toDataFrame
60+
val df = self.toDataFrame
6061
.setSpatialColumnRole(SPATIAL_KEY_COLUMN, self.metadata)
6162
.setTemporalColumnRole(TEMPORAL_KEY_COLUMN)
63+
val defName = TILE_COLUMN.columnName
64+
df.mapWhen(_ tileColumnName != defName, _.withColumnRenamed(defName, tileColumnName))
6265
.certify
6366
}
6467
}

core/src/test/scala/astraea/spark/rasterframes/RasterFrameSpec.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class RasterFrameSpec extends TestEnvironment with MetadataKeys
7474
)
7575

7676
assert(rf.count() === 4)
77+
78+
val cols = tileLayerRDD.toRF("foo").columns
79+
assert(!cols.contains("tile"))
80+
assert(cols.contains("foo"))
7781
}
7882

7983
it("should implicitly convert from spatiotemporal layer type") {
@@ -93,6 +97,9 @@ class RasterFrameSpec extends TestEnvironment with MetadataKeys
9397
println(rf.schema.prettyJson)
9498
throw ex
9599
}
100+
val cols = tileLayerRDD.toRF("foo").columns
101+
assert(!cols.contains("tile"))
102+
assert(cols.contains("foo"))
96103
}
97104

98105
it("should implicitly convert layer of TileFeature") {

0 commit comments

Comments
 (0)