gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:29:12 25 4
gpt4 key购买 nike

为什么在 Scala Spark 应用程序中初始化 SQLContext 后导入隐式 SqlContext.implicits._。

当 import 放在 object 之外时,似乎有问题。

我来自 java 背景,我不了解 def 对象中导入语句的用法。

val sqlContext = new SQLContext(sc)

import sqlContext.implicits._
import sqlContext._

最佳答案

导入在外部不起作用,因为 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 的实例时你能导入包含所有隐式的内部对象定义吗?

关于scala - 为什么在 scala spark 应用程序中初始化 SQLContext 后导入隐式 SqlContext.implicits._,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42503558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com