I imported a PostgreSQL table into spark as a dataframe using Scala. The dataframe looks like
user_id | log_dt
--------| -------
96 | 2004-10-19 10:23:54.0
1020 | 2017-01-12 12:12:14.931652
I am transforming this dataframe to have the data format for log_dt as yyyy-MM-dd hh:mm:ss.SSSSSS
. To achieve this I used the following code to convert the log_dt to timestamp format using unix_timestamp
function.
val tablereader1 = tablereader1Df.withColumn("log_dt",unix_timestamp(tablereader1Df("log_dt"),"yyyy-MM-dd hh:mm:ss.SSSSSS").cast("timestamp"))
When I print to print the tablereader1 dataframe using the command tablereader1.show()
I get the following result
user_id | log_dt
--------| -------
96 | 2004-10-19 10:23:54.0
1020 | 2017-01-12 12:12:14.0
How can I retain the microseconds as part of the timestamp? Any suggestions are appreciated.