The input JSON file is shown below.
The SBT library dependencies are shown below for reference.
scalaVersion := "2.11.12"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.3.0"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.3.0"
The Scala program is provided below.
The converted ORC file is shown below.import org.apache.spark.sql.{SaveMode, SparkSession} object JSONToORCConverter extends App { val spark = SparkSession.builder() .master("local") .appName("TSVToORConverter") .config("spark.sql.orc.impl", "native") .getOrCreate() val inputJSONFile = "C:\\data\\data.json"val outputORCFile = "C:\\data\\out_data_json" val df = spark .read .format("json") .option("multiline", "true") .load(inputJSONFile) df .write .mode(SaveMode.Overwrite) .option("header","true") .orc(outputORCFile) }
That's all!
No comments:
Post a Comment