【问题标题】:Spark Dataframes , WithColumn星火数据帧,WithColumn
【发布时间】:2017-02-27 13:00:03
【问题描述】:

我在 Spark-shell 中尝试了以下代码,它运行良好。

val df2 = df3.withColumn("Escore", when($"col2" === $"col3",10).otherwise(0))orderBy(asc("col2"),desc("Escore"),desc("col5"))

但是当我在 IntelliJ 的 Scala 中使用 SBT 尝试相同的命令时,我遇到了以下错误。

在 Scala IDE 中:

val df2: DataFrame = df3.withColumn("Escore": String,when($"col2" === $"col3",10).otherwise(0))orderBy(asc("col2"),desc("Escore"),desc("col5"))

错误:无法解析符号“WHEN”。

谁能提供如何在 IntelliJ Scala 中编写 withColumn 数据帧的示例代码或语法。

我的 SBT 是:

name := "SparkSqlExample"

version := "1.0"

scalaVersion := "2.11.5"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.5.1"

libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.5.1"

【问题讨论】:

    标签: scala intellij-idea spark-dataframe


    【解决方案1】:

    我也试过 spark-shell 这工作正常,但即使在 intelliJ 它工作正常。我想你忘记导入 sql 函数了。

    import org.apache.spark.sql.functions._

    试试这个。如果不添加评论,这将解决问题 谢谢

    【讨论】:

      猜你喜欢
      • 2019-04-01
      • 1970-01-01
      • 2020-08-09
      • 2018-02-15
      • 2019-04-12
      • 2016-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多