问题
I have a script running in a paragraph with the Spark interpreter in Zeppelin. It has an import and the name imported can be resolved from the global namespace and also from a function, but not from a method inside a class.
This runs well on my computer's installation of Scala (2.12) but it doesn't work in Zeppelin (Scala 2.11).
import java.util.Calendar
def myFun: String = {
// this works
return Calendar.getInstance.toString
}
class MyClass {
def myFun(): String = {
// this doesn't
return Calendar.getInstance.toString
// this works
return java.util.Calendar.getInstance.toString
}
}
The error message is like:
import java.util.Calendar
myFun: String
<console>:15: error: not found: value Calendar
return Calendar.getInstance.toString
What am I missing?
回答1:
In 0.8.0 Zeppelin has introduced a new SparkInterpreter I suppose due to which the global imports don't work and the imports have to be scoped within a wrapper.
As a workaround, the property zeppelin.spark.useNew can be set to the value "false". This disables the sparks new interpreter.
来源:https://stackoverflow.com/questions/52076014/how-is-an-imported-name-resolved-in-scala-spark-zeppelin