Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. {"name":"Michael"}
  2. {"name":"Andy", "age":30}
  3. {"name":"Justin", "age":19}
  4.  
  5. import org.apache.spark.sql.SparkSession
  6.  
  7. val sparkSession = SparkSession.builder
  8. .master("local")
  9. .appName("my-spark-app")
  10. .config("spark.some.config.option", "config-value")
  11. .getOrCreate()
  12.  
  13. val peopleDF = sparkSession.sparkContext.
  14. textFile("C:/Users/Desktop/Spark/people.json").
  15. map(_.split(",")).
  16. map(attributes => Person(attributes(0),attributes(1).trim.toInt)).
  17. toDS()
  18.  
  19. peopleDF.createOrReplaceTempView("person")
  20.  
  21. val teenagersDF = sparkSession.sql("select name, age FROM person")
  22.  
  23. teenagersDF.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement