Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to use sqlContext? Getting an error!

Solved Go to solution
Highlighted

How to use sqlContext? Getting an error!

sqlcontext.png Please find snapshot attached for the issue.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to use sqlContext? Getting an error!

@sudhir reddy

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.

View solution in original post

10 REPLIES 10
Highlighted

Re: How to use sqlContext? Getting an error!

Super Mentor

@sudhir reddy

Are you using Spark2?

Have you set the Env variable as following before opening the shell?

# export SPARK_MAJOR_VERSION=2
# spark-shell

.

Highlighted

Re: How to use sqlContext? Getting an error!

Yes, using spark2. It is by default using Spark2. What else should I try? @Jay Kumar SenSharma

Highlighted

Re: How to use sqlContext? Getting an error!

Super Mentor

@sudhir reddy

Can you please share the complete output along with the command that you ran?

Highlighted

Re: How to use sqlContext? Getting an error!

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

Highlighted

Re: How to use sqlContext? Getting an error!

Super Mentor

@sudhir reddy

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

Highlighted

Re: How to use sqlContext? Getting an error!

@sudhir reddy

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.

View solution in original post

Highlighted

Re: How to use sqlContext? Getting an error!

Thanks! It worked.

Highlighted

Re: How to use sqlContext? Getting an error!

New Contributor
val sc: SparkContext // An existing SparkContext.
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val rd = sqlContext.read.json("user/root/Example2.JSON")
Highlighted

Re: How to use sqlContext? Getting an error!

Thank you!

Don't have an account?
Coming from Hortonworks? Activate your account here