How is an imported name resolved in Scala? (Spark / Zeppelin)

和自甴很熟 提交于 2019-12-10 08:50:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!