Skip to content

Instantly share code, notes, and snippets.

@afranzi
Created May 30, 2019 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afranzi/2d5f82c09476d9d7d13ecdfbf1d9edce to your computer and use it in GitHub Desktop.
Save afranzi/2d5f82c09476d9d7d13ecdfbf1d9edce to your computer and use it in GitHub Desktop.
trait SparkWriter {
def write(df: DataFrame, mode: WriteMode = Overwrite): Unit
}
class SparkJsonWriter(path: String, partitions: Int = 1) extends SparkWriter {
def write(df: DataFrame, mode: WriteMode = Overwrite): Unit = {
df
.coalesce(partitions)
.write
.mode(mode)
.json(path)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment