Jupyter 中使用 Apache Toree 内核的有限 Scala 语法

Limited Scala Syntax with Apache Toree Kernel in Jupyter

OS X El Capitan 10.11.6
Spark 2.2.0 (local)
Scala 2.11.8
Apache Toree Jupyter Kernel 0.2.0

根据我从 , I've successfully included a Spark - Scala kernel to my Jupyter notebook by using this Toree installer 收到的说明。但是,我注意到 Scala 语法非常有限。这里有两个例子:

1.无法手动创建 DataFrame

以下代码在终端 Spark 中运行 shell:

val test = Seq(
        ("Brandon", "Erica"),
        ("Allen", "Sarabeth"),
        ("Jared", "Kyler")).
    toDF("guy", "girl")

但是当尝试在 Jupyter 中使用 Spark - Scala 内核 运行 时,我收到以下错误:

Name: Compile Error
Message: <console>:21: error: value toDF is not a member of Seq[(String, String)]
possible cause: maybe a semicolon is missing before `value toDF'?
       toDF("guy", "girl")
       ^

2。无法使用特定语法调用列名 似乎 Jupyter Spark - Scala 内核在使用 $"columnName" 调用时无法识别列,但可以识别使用 df.col("columnName") 调用的列。 $"columnName" 语法抛出以下错误:

Name: Compile Error
Message: <console>:31: error: value $ is not a member of StringContext
   df.where($"columnName" =!= "NA").

我认为有一个高级解决方案可以让所有 Spark Scala 语法在 Jupyter 中使用,期待社区的支持。

我找到了 another post 的答案也解决了我的问题:

val sqlC = new org.apache.spark.sql.SQLContext(sc)
import sqlC.implicits._ 

运行 notebook 开头的这一点消除了我之前遇到的所有语法限制。