Created
December 8, 2016 13:43
-
-
Save tmcgrath/d40435667d261fbc2a593dc331cb2c8a to your computer and use it in GitHub Desktop.
SparkSQL with json file example
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
// download sample json | |
http://bit.ly/2gY39Ay | |
// start spark-shell in same directory as where customers.json | |
// is downloaded | |
val customers = sqlContext.jsonFile("customers.json") | |
// register a temp table | |
customers.registerTempTable("customers") | |
// create dataframe with sql | |
val firstCityState = sqlContext.sql("SELECT first_name, address.city, address.state FROM customers") | |
firstCityState.show | |
firstCityState.collect.foreach(println) | |
// etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment