在Scala Spark应用程序中初始化SQLContext后,为什么要导入隐式SqlContext.implicits._ [英] Why import implicit SqlContext.implicits._ after initializing SQLContext in a scala spark application
问题描述
为什么要在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屋!