You could use expr() function to achieve the same. .withColumn("newColumn",expr(s"case when score>3 then 'good' else 'bad' end")) -- Raghavendra
On Fri, Feb 11, 2022 at 5:59 PM frakass <capitnfrak...@free.fr> wrote: > Hello > > I have a column whose value (Int type as score) is from 0 to 5. > I want to query that, when the score > 3, classified as "good". else > classified as "bad". > How do I implement that? A UDF like something as this? > > scala> implicit class Foo(i:Int) { > | def classAs(f:Int=>String) = f(i) > | } > class Foo > > scala> 4.classAs { x => if (x > 3) "good" else "bad" } > val res13: String = good > > scala> 2.classAs { x => if (x > 3) "good" else "bad" } > val res14: String = bad > > > Thank you. > > --------------------------------------------------------------------- > To unsubscribe e-mail: user-unsubscr...@spark.apache.org > >