如何在 Scala 中解析导入的名称?(火花/齐柏林飞艇) [英] How is an imported name resolved in Scala? (Spark / Zeppelin)
问题描述
我在 Zeppelin 中使用 Spark 解释器在一个段落中运行了一个脚本.它有一个导入,导入的名称可以从全局命名空间和函数解析,但不能从类中的方法解析.
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.
这在我计算机上安装的 Scala (2.12) 上运行良好,但在 Zeppelin (Scala 2.11) 中不起作用.
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
}
}
错误信息如下:
import java.util.Calendar
myFun: String
<console>:15: error: not found: value Calendar
return Calendar.getInstance.toString
我错过了什么?
推荐答案
在 0.8.0 中,Zeppelin 引入了一个新的 SparkInterpreter,我想是因为全局导入不起作用,导入必须在包装器内进行限定.
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.
作为一种解决方法,可以将属性 zeppelin.spark.useNew 设置为值false".这会禁用 sparks 新解释器.
As a workaround, the property zeppelin.spark.useNew can be set to the value "false". This disables the sparks new interpreter.
这篇关于如何在 Scala 中解析导入的名称?(火花/齐柏林飞艇)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!