I have a spark app, that need to convert from string to timestamp below is my code.
val df = sc.parallelize(Seq("09/18/2017","")).toDF("sDate")
+----------+
| sDate|
+----------+
|09/18/2017|
| |
+----------+
val ts = unix_timestamp($"sDate","MM/dd/yyyy").cast("timestamp")
df.withColumn("ts", ts).show()
+----------+--------------------+
| sDate| ts|
+----------+--------------------+
|09/18/2017|2017-09-18 00:00:...|
| | null|
+----------+--------------------+
The conversion is doing good, but if the value is empty , I'm getting null after casting.
Is there any way to return empty if the source value is empty.