I am new to pyspark and Spark SQL. I have a dataframe with one column having date time values in string which I need to convert/cast to timestamp.
Dataframe Format:
+--------------------+------------------------------+
| value| time_from_text|
+--------------------+------------------------------+
|dummy |2020-04-19T23:49:52.020000453Z|
|dummy |2020-04-22T23:52:52.020000453Z|
+--------------------+------------------------------+
Now, I looked at this post and tried the following code snippet:
result.withColumn("Timestamp",unix_timestamp("time_from_text", "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'").cast(TimestampType()))
This did work in my earlier case where my spark version was 3.1.1. However, I needed to switch back to 2.4.6 and here, the same code is giving me null as the output for the timestamp!
I tried many different ways but am not able to cast the timestamp.
Any pointers would be appreciated. Thanks for the help!