-
-
Save Sathiyarajan/867062da3b28a30bf172fb7775a4d37c to your computer and use it in GitHub Desktop.
SparkSQL with json file example
This file contains 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