Created 07-04-2018 10:59 AM
sqlcontext.png Please find snapshot attached for the issue.
Created 07-04-2018 12:16 PM
SqlContext is not available by default in Spark2 shell.
Create a sqlContext using below statement after launching the spark-shell and then you can read the json using this sqlContext.
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
Let me know if this helps.
Created 07-04-2018 11:05 AM
Are you using Spark2?
Have you set the Env variable as following before opening the shell?
# export SPARK_MAJOR_VERSION=2 # spark-shell
.
Created 07-04-2018 11:12 AM
Yes, using spark2. It is by default using Spark2. What else should I try? @Jay Kumar SenSharma
Created 07-04-2018 11:14 AM
Created 07-04-2018 11:18 AM
val rd = sqlContext.read.json("/user/root/Example2.JSON"); //Used this command.
<console>:23: error: not found: value sqlContext
val rd = sqlContext.read.json("/user/root/Example2.JSON");
^ //Got this output @Jay Kumar SenSharm
Created 07-04-2018 11:27 AM
How are you logging in to the Shell? Which command are you using to login in to the spark shell ? Which mode?
For example when you run "spark-shell" then you will see lots of output ... we need that complete output.
Example
# spark-shell <br>
.
As much information you can provide about your issue ... there are possibilities that your issue will get resolved faster. Else there will be more interactions to know which HDP version are you using ? What is the logging happening? ...etc
Created 07-04-2018 12:16 PM
SqlContext is not available by default in Spark2 shell.
Create a sqlContext using below statement after launching the spark-shell and then you can read the json using this sqlContext.
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
Let me know if this helps.
Created 07-04-2018 01:08 PM
Thanks! It worked.
Created 07-04-2018 12:25 PM
val sc: SparkContext // An existing SparkContext. val sqlContext = new org.apache.spark.sql.SQLContext(sc) val rd = sqlContext.read.json("user/root/Example2.JSON")
Created 07-04-2018 01:09 PM
Thank you!