【问题标题】:Limited Scala Syntax with Apache Toree Kernel in JupyterJupyter 中使用 Apache Toree 内核的有限 Scala 语法
【发布时间】:2017-11-06 21:35:28
【问题描述】:
OS X El Capitan 10.11.6
Spark 2.2.0 (local)
Scala 2.11.8
Apache Toree Jupyter Kernel 0.2.0

根据我从this post 收到的说明,我已使用this Toree installer 成功地将Spark - Scala 内核包含到我的Jupyter 笔记本中。但是,我注意到 Scala 语法非常有限。这里有两个例子:

1.无法手动创建 DataFrame

以下代码在终端 Spark shell 中工作:

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

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

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 中使用,并期待社区的支持。

【问题讨论】:

    标签: scala apache-spark jupyter-notebook apache-toree


    【解决方案1】:

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

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

    在笔记本的开头运行它已经缓解了我之前遇到的所有语法限制。

    【讨论】:

      猜你喜欢
      • 2017-04-11
      • 2017-03-18
      • 1970-01-01
      • 2017-04-03
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多