March 15, 2022 at 12:30 am
So going all the way back to the beginning - using sparkSQL instead of T-SQL, what you need to do is convert your integer time to a string in the format HH:MM:SS and convert your date to a string in the format YYYY-MM-DD. Concatenate those together into the format 'YYYY-MM-DD HH:MM:SS' and use the to_timestamp function to convert that string to a valid timestamp.
Since none of this is anything that we would do in T-SQL it is not something where we can provide any real help.
Not quite true. The concept of integer division and modulo both exist in Spark SQL and, if the OP has Spark 3.0, they have that MAKE_TIMESTAMP function, which is nearly identical to DATETIMEFROMPARTS.
See my previous post just above yours for links.
--Jeff Moden
March 15, 2022 at 9:16 pm
Jeffrey Williams wrote:So going all the way back to the beginning - using sparkSQL instead of T-SQL, what you need to do is convert your integer time to a string in the format HH:MM:SS and convert your date to a string in the format YYYY-MM-DD. Concatenate those together into the format 'YYYY-MM-DD HH:MM:SS' and use the to_timestamp function to convert that string to a valid timestamp.
Since none of this is anything that we would do in T-SQL it is not something where we can provide any real help.
Not quite true. The concept of integer division and modulo both exist in Spark SQL and, if the OP has Spark 3.0, they have that MAKE_TIMESTAMP function, which is nearly identical to DATETIMEFROMPARTS.
See my previous post just above yours for links.
That is going to just as difficult - if not more so as you have to first get the year, month, day, hour, minute and second from the integer values to pass to MAKE_TIMESTAMP.
However - using TO_TIMESTAMP with the format option, it should just be: TO_TIMESTAMP(CONCAT_WS(' ', CAST(LAST_MOD_DATE AS char(8)), CAST(LAST_MOD_TIME AS char(6))), 'yyyyMMdd HHmmss')
Validate the format - it should be correct. You could remove the separator and just use CONCAT without the space in the format.
Jeffrey Williams
Problems are opportunities brilliantly disguised as insurmountable obstacles.
How to post questions to get better answers faster
Managing Transaction Logs
March 16, 2022 at 3:24 am
Jeff Moden wrote:Jeffrey Williams wrote:So going all the way back to the beginning - using sparkSQL instead of T-SQL, what you need to do is convert your integer time to a string in the format HH:MM:SS and convert your date to a string in the format YYYY-MM-DD. Concatenate those together into the format 'YYYY-MM-DD HH:MM:SS' and use the to_timestamp function to convert that string to a valid timestamp.
Since none of this is anything that we would do in T-SQL it is not something where we can provide any real help.
Not quite true. The concept of integer division and modulo both exist in Spark SQL and, if the OP has Spark 3.0, they have that MAKE_TIMESTAMP function, which is nearly identical to DATETIMEFROMPARTS.
See my previous post just above yours for links.
That is going to just as difficult - if not more so as you have to first get the year, month, day, hour, minute and second from the integer values to pass to MAKE_TIMESTAMP.
However - using TO_TIMESTAMP with the format option, it should just be: TO_TIMESTAMP(CONCAT_WS(' ', CAST(LAST_MOD_DATE AS char(8)), CAST(LAST_MOD_TIME AS char(6))), 'yyyyMMdd HHmmss')
Validate the format - it should be correct. You could remove the separator and just use CONCAT without the space in the format.
If you do it with the integer math that I used in the T-SQL method I previously posted, it's not that much code and it blows away any character based transformations.
--Jeff Moden
Viewing 3 posts - 31 through 32 (of 32 total)
You must be logged in to reply to this topic. Login to reply