-
-
Save vijayhack/5de4558bcc7c7d9e46cd357688dde1b2 to your computer and use it in GitHub Desktop.
Mapping over a Spark DataFrame, via RDD, back to DataFrame so we can use the databricks API to write to an Avro file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //import sqlContext.implicits._ | |
| import com.databricks.spark.avro._ | |
| import org.apache.spark.sql._ | |
| import org.apache.spark.sql.types._ | |
| //val inschema = StructType(List(StructField("name", StringType, true), StructField("age", IntegerType, true))) | |
| val outschema = StructType(List(StructField("summary", StringType, true))) | |
| val input = sc.parallelize(List(Row("fred", 34), Row("wilma", 33))) | |
| val out = input.map{ case Row(name, age) => Row(s"$name is $age") } | |
| val df = sqlContext.createDataFrame(out, outschema) | |
| df.write.avro("df-mapping.avro") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment