0

I'm new to Spark. I'm trying to run the following code in Spark shell:

import org.apache.spark.api.java.JavaSparkContext
import org.apache.hadoop.conf
JavaSparkContext context = new JavaSparkContext(conf);

But I'm getting the following error:

<console>:32: error: value context is not a member of object 
org.apache.spark.api.java.JavaSparkContext
val $ires10 = JavaSparkContext.context
                           ^
<console>:29: error: value context is not a member of object 
org.apache.spark.api.java.JavaSparkContext
     JavaSparkContext context = new JavaSparkContext(conf);

Is there any import statement that I'm missing? I also added

import org.apache.spark.api.java.JavaSparkContext._

but it still didn't work. Please help.

0

1 Answer 1

2

UPDATE: Whether the configuration is valid or not is something you'll have to work on, but this addresses the error you asked about in your original question.

Your code is (almost) valid Java, but not valid Scala. Did you mean something like this:

import org.apache.spark.api.java.JavaSparkContext

val context = new JavaSparkContext()

Alternatively, since you're using Scala, you might want to try this instead.

import org.apache.spark.SparkContext

val context = new SparkContext()

As for the error you report, Scala will treat the statement JavaSparkContext context as a reference to a member named context of an object named JavaSparkContext - and not as a variable declaration as it is in Java.

Sign up to request clarification or add additional context in comments.

2 Comments

I did try that earlier, but I got an error saying <console>:38: error: package org.apache.hadoop.conf is not a value
That's probably because org.apache.hadoop.conf is a package, not a configuration instance. You need to determine how to create the object that you pass to JavaSparkContext's constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.