错误:未找到:值点亮/何时 - spark scala

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39592675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:39:33  来源:igfitidea点击:

Error: not found: value lit/when - spark scala

scalamavenintellij-ideaapache-spark

提问by Avijit

I am using scala, spark, IntelliJ and maven.

我正在使用 Scala、Spark、IntelliJ 和 maven。

I have used below code :

我使用了以下代码:

val joinCondition = when($"exp.fnal_expr_dt" >= $"exp.nonfnal_expr_dt",
$"exp.manr_cd"===$"score.MANR_CD")

val score = exprDF.as("exp").join(scoreDF.as("score"),joinCondition,"inner")

and

val score= list.withColumn("scr", lit(0))

But when try to build using maven, getting below errors -

但是当尝试使用 maven 构建时,出现以下错误 -

error: not found: value when

错误:未找到:值时

and

error: not found: value lit

错误:未找到:值点亮

For $and ===I have used import sqlContext.implicits.StringToColumnand it is working fine. No error occurred at the time of maven build.But for lit(0)and whenwhat I need to import or is there any other way resolve the issue.

对于$===我用import sqlContext.implicits.StringToColumn它工作正常。在Maven的build.But的的时间没有出现错误lit(0)when我需要进口或者是有任何其他方式解决这个问题是什么。

回答by eliasah

Let's consider the following context :

让我们考虑以下上下文:

val spark : SparkSession = _ // or val sqlContext: SQLContext = new SQLContext(sc) for 1.x
val list: DataFrame = ???

To use whenand lit, you'll need to import the proper functions :

要使用whenand lit,您需要导入正确的函数:

import org.apache.spark.sql.functions.{col, lit, when}

Now you can use them as followed :

现在您可以按如下方式使用它们:

list.select(when(col("column_name").isNotNull, lit(1)))

Now you can use lit also in your code :

现在你也可以在你的代码中使用 lit :

val score = list.withColumn("scr", lit(0))