Support Questions
Find answers, ask questions, and share your expertise

Need to change the value of column if another column matches with a particular string in scala spark.

I have a dataset with schema ( case class GuestHits ( val LOCATION:String ,

val TIMESTAMP_DT:String ,

val DEVICE_ID:String ,

val SERVICE:String ,

val HOSTNAME:String ,

val URL:String ,

val DST:String ,

val DST_PORT:String ,

val RCVD:String ,

val SENT:String ))

I need to convert column HOSTNAME into upper case if URL matches with "some string".

Tried "when otherwise" function also "translate" func but none of them is working . Please help if anybody knows.

1 REPLY 1

Expert Contributor

What about trying to use a standard `SQL` syntax first instead of Scala? Spark supports `CASE WHEN` syntax in `sql()`.

CASE WHEN ... THEN ... ELSE ... END