Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-494] Raster data source cannot write to HDFS #1235

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private class RasterFileWriter(savePath: String,
val rasterFilePath = getRasterFilePath(row, dataSchema, rasterOptions)
// write the image to file
try {
val out = hfs.create(new Path(Paths.get(savePath, new Path(rasterFilePath).getName).toString))
val out = hfs.create(new Path(savePath, new Path(rasterFilePath).getName))
out.write(rasterRaw)
out.close()
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.apache.sedona.sql

import com.google.common.math.DoubleMath
import org.apache.hadoop.fs.FileUtil
import org.apache.hadoop.hdfs.{HdfsConfiguration, MiniDFSCluster}
import org.apache.log4j.{Level, Logger}
import org.apache.sedona.common.Functions.{frechetDistance, hausdorffDistance}
import org.apache.sedona.common.Predicates.dWithin
Expand All @@ -28,6 +30,8 @@ import org.apache.spark.sql.DataFrame
import org.locationtech.jts.geom._
import org.scalatest.{BeforeAndAfterAll, FunSpec}

import java.io.File

trait TestBaseScala extends FunSpec with BeforeAndAfterAll {
Logger.getRootLogger.setLevel(Level.WARN)
Logger.getLogger("org.apache").setLevel(Level.WARN)
Expand Down Expand Up @@ -74,10 +78,19 @@ trait TestBaseScala extends FunSpec with BeforeAndAfterAll {
val buildingDataLocation: String = resourceFolder + "813_buildings_test.csv"
val smallRasterDataLocation: String = resourceFolder + "raster/test1.tiff"
private val factory = new GeometryFactory()
var hdfsURI: String = _


override def beforeAll(): Unit = {
SedonaContext.create(sparkSession)
// Set up HDFS minicluster
val baseDir = new File("./target/hdfs/").getAbsoluteFile
FileUtil.fullyDelete(baseDir)
val hdfsConf = new HdfsConfiguration
hdfsConf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, baseDir.getAbsolutePath)
val builder = new MiniDFSCluster.Builder(hdfsConf)
val hdfsCluster = builder.build
hdfsURI = "hdfs://127.0.0.1:" + hdfsCluster.getNameNodePort + "/"
}

override def afterAll(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
package org.apache.sedona.sql

import org.apache.commons.io.FileUtils
import org.apache.sedona.common.raster.RasterAccessors
import org.apache.spark.sql.SaveMode
import org.apache.spark.sql.sedona_sql.expressions.raster.RS_Metadata
import org.junit.Assert.assertEquals
import org.scalatest.{BeforeAndAfter, GivenWhenThen}

Expand Down Expand Up @@ -149,6 +147,15 @@ class rasterIOTest extends TestBaseScala with BeforeAndAfter with GivenWhenThen
rasterDf = df.selectExpr("RS_FromArcInfoAsciiGrid(content)")
assert(rasterDf.count() == rasterCount)
}

it("should read geotiff using binary source and write geotiff back to hdfs using raster source") {
var rasterDf = sparkSession.read.format("binaryFile").load(rasterdatalocation)
val rasterCount = rasterDf.count()
rasterDf.write.format("raster").mode(SaveMode.Overwrite).save(hdfsURI + "/raster-written")
rasterDf = sparkSession.read.format("binaryFile").load(hdfsURI + "/raster-written/*")
rasterDf = rasterDf.selectExpr("RS_FromGeoTiff(content)")
assert(rasterDf.count() == rasterCount)
}
}

override def afterAll(): Unit = FileUtils.deleteDirectory(new File(tempDir))
Expand Down
Loading