错误:未找到:值lit / when - spark scala [英] Error: not found: value lit/when - spark scala

查看:1090
本文介绍了错误:未找到:值lit / when - spark scala的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用scala,spark,IntelliJ和maven。

I am using scala, spark, IntelliJ and maven.

我使用了以下代码:

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")

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

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

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


错误:未找到:值

error: not found: value when


错误:未找到:值已点亮

error: not found: value lit

对于 $ === 我使用了 import sqlContext.implicits.StringToColumn 并且工作正常。在maven build时没有发生错误。但是 lit(0)我需要导入或有什么其他方法可以解决这个问题。

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

推荐答案

让我们考虑以下背景:

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

在和<$ c $时使用 c>点亮,您需要导入正确的函数:

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

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 :

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

这篇关于错误:未找到:值lit / when - spark scala的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆