在Scala Spark应用程序中初始化SQLContext后,为什么要导入隐式SqlContext.implicits._ [英] Why import implicit SqlContext.implicits._ after initializing SQLContext in a scala spark application

查看:93
本文介绍了在Scala Spark应用程序中初始化SQLContext后,为什么要导入隐式SqlContext.implicits._的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要在scala spark应用程序中初始化SQLContext后导入隐式SqlContext.implicits ._.

Why import implicit SqlContext.implicits._ after initializing SQLContext in a scala spark application.

将导入放置在对象之外时,似乎有问题.

when import is put outside the object , there seems to be an issue.

我来自java的背景,不了解def对象中import语句的用法.

I am from a java back ground , where am not understanding the usage of import statements within a def object.

val sqlContext = new SQLContext(sc)

import sqlContext.implicits._
import sqlContext._

推荐答案

由于

The import doesn't work externally because the implicits object is defined inside the SQLContext class:

* :: Experimental ::
* (Scala-specific) Implicit methods available in Scala for converting
* common Scala objects into `DataFrame`s.
*
* {{{
*   val sqlContext = new SQLContext(sc)
*   import sqlContext.implicits._
* }}}
@Experimental
@InterfaceStability.Evolving
object implicits extends SQLImplicits with Serializable {
  protected override def _sqlContext: SQLContext = self
}

因此,只有拥有 SQLContext 的实例后,才能导入包含所有隐式对象的内部对象定义.

Thus, only once you have an instance of SQLContext can you import the internal object definition containing all the implicits.

这篇关于在Scala Spark应用程序中初始化SQLContext后,为什么要导入隐式SqlContext.implicits._的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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