简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM