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

前端 未结 1 1817
广开言路
广开言路 2021-01-05 09:08

I am using scala, spark, IntelliJ and maven.

I have used below code :

val joinCondition = when($\"exp.fnal_expr_dt\" >= $\"exp.nonfnal_expr_dt\",         


        
相关标签:
1条回答
  • 2021-01-05 10:10

    Let's consider the following context :

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

    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))
    
    0 讨论(0)
提交回复
热议问题