I imported a PostgreSQL table into a spark as a data frame using Scala. The data block looks like
user_id | log_dt --------| ------- 96 | 2004-10-19 10:23:54.0 1020 | 2017-01-12 12:12:14.931652
I will convert this data frame to have a data format for log_dt like yyyy-MM-dd hh:mm:ss.SSSSSS . To do this, I used the following code to convert the log_dt format to the timestamp format using the 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 a data block tablereader1 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 to save microseconds as part of a timestamp? Any suggestions are welcome.
java scala datetime apache-spark apache-spark-sql
Sid
source share