Unable to write files after scala and spark upgrade

71 Views Asked by At

My project was previously using Scala version 2.11.12 which I have upgraded to 2.12.10 and the Spark version has been upgraded from 2.4.0 to 3.1.2. See the build.sbt file below with the rest of the project dependencies and versions:

scalaVersion := "2.12.10"
val sparkVersion = "3.1.2"

libraryDependencies += "org.apache.spark" %% "spark-core" % sparkVersion % "provided"
libraryDependencies += "org.apache.spark" %% "spark-sql" % sparkVersion % "provided"
libraryDependencies += "org.apache.spark" %% "spark-hive" % sparkVersion % "provided"

libraryDependencies += "org.xerial.snappy" % "snappy-java" % "1.1.4"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test, it"

libraryDependencies += "com.holdenkarau" %% "spark-testing-base" % "3.1.2_1.1.0" % "test, it"

libraryDependencies += "com.github.pureconfig" %% "pureconfig" % "0.12.1"
libraryDependencies += "com.typesafe" % "config" % "1.3.2"
libraryDependencies += "org.pegdown" % "pegdown" % "1.1.0" % "test, it"

libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.1"

libraryDependencies += "com.github.pathikrit" %% "better-files" % "3.8.0"

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"

libraryDependencies += "com.amazon.deequ" % "deequ" % "2.0.0-spark-3.1" excludeAll (
  ExclusionRule(organization = "org.apache.spark")
)

libraryDependencies += "net.liftweb" %% "lift-json" % "3.4.0"

libraryDependencies += "com.crealytics" %% "spark-excel" % "0.13.1"

The app is building fine after the upgrade but it is unable to write files to the filesystem which was working fine before the upgrade. I havent made any code changes to the write logic.

The relevant portion of code that writes to the files is shown below.

    val inputStream = getClass.getResourceAsStream(resourcePath)

    val conf = spark.sparkContext.hadoopConfiguration
    val fs = FileSystem.get(spark.sparkContext.hadoopConfiguration)
    val output = fs.create(new Path(outputPath))
    IOUtils.copyBytes(inputStream, output.getWrappedStream, conf, true)

I am wondering if IOUtils is not compatible with the new Scala/Spark versions?

0

There are 0 best solutions below