如何在Scala中解析导入的名称? (火花/齐柏林飞艇) [英] How is an imported name resolved in Scala? (Spark / Zeppelin)

查看:104
本文介绍了如何在Scala中解析导入的名称? (火花/齐柏林飞艇)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆