0

I have got a problem when I tired to compile my scala program with SBT. I have import the class I need .Here is part of my code.

import java.io.File
import java.io.FileWriter
import java.io.PrintWriter
import java.io.IOException
import org.apache.spark.{SparkConf,SparkContext}
import org.apache.spark.rdd.PairRDDFunctions
import scala.util.Random    
......
val data=sc.textFile(path)
    val kv=data.map{s=>
      val a=s.split(",")
      (a(0),a(1))
    }.cache()
    kv.first()
    val start=System.currentTimeMillis()
    for(tg<-target){
      kv.lookup(tg.toString)
    }

The error detail is :

value lookup is not a member of org.apache.spark.rdd.RDD[(String, String)]
[error]           kv.lookup(tg.toString)

What confused me is I have import import org.apache.spark.rdd.PairRDDFunctions, but it doesn't work . And when I run this in Spark-shell ,it runs well.

1 Answer 1

1

import org.apache.spark.SparkContext._ to have access to the implicits that let you use PairRDDFunctions on a RDD of type (K,V). There's no need to directly import PairRDDFunctions

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

2 Comments

Thanks for you help.But I met new problem like this :[error] in package org.apache.hadoop which is not available. [error] It may be completely missing from the current classpath, or the version on [error] the classpath might be incompatible with the version used when compiling SparkContext.class. [error] for(i<- 0 to totalnum-1){
That's a different question. Please create a new question for it. But it sounds like a classpath or version conflict, so check those carefully.

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.