H.Z. H.Z. - 3 months ago 26
Scala Question

How to pass sqlContext implicitly to a function?

I have a function in a Scala object which has the following signature

def f(v1:Int)(implicit sqlContext: SQLContext)

when I try to call this function from spark-shell I call it like


and I expect the existing sqlContext gets passed to it implicitly but it doesn't. How can I make it to work so the sqlContext get passed to this function automatically?


You just need to add a SQLContext implicitly to the same context which you are calling your function:

implicit val sqlContext = new SQLContext() // just an example
// and then

If you are using apacha Spark, you can use this import:

import sqlContext.implicits._