Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to present a duration (in seconds) stored in a BIGINT in the format "hh:mm:ss"?

João Pedro Gomes Ramalho
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 30, 2024

I've already tried modifying the query to fetch the data using SQLite with something like this:
printf('%02d:%02d:%02d', AVG(time_in_status) / 3600, (AVG(time_in_status) % 3600) / 60, AVG(time_in_status) % 60)

but without much success.

I'm using Atlassian Datalake/Analytics to try to display this duration.
Has anybody already went through this process? I'm open to suggestions :)

1 answer

0 votes
Pears Whims
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 1, 2024

Hi @João Pedro Gomes Ramalho ,

Can You please try one of those approaches, and let me know if any of them work.

 

strftime

SQL lite can support a built-in function strftime:

SELECT
strftime('%H:%M:%S', AVG(time_in_status), 'unixepoch') AS formatted_duration
FROM your_table;

 

casting

Your original query may not be working exactly due to casting issues. Consider using explicit casting

SELECT
printf('%02d:%02d:%02d',
CAST(AVG(time_in_status) AS INTEGER) / 3600,
(CAST(AVG(time_in_status) AS INTEGER) % 3600) / 60,
CAST(AVG(time_in_status) AS INTEGER) % 60
) AS formatted_duration
FROM your_table;

 

In case of any issues, may You please provide a test value for the timestamp as well as the error message?

Thank You!

Pears.

 

Pears Whims
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2024

Hello, @João Pedro Gomes Ramalho .

May you please let me know if the solution help You to progress on Your case?

Best of luck,
Pears.

João Pedro Gomes Ramalho
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 30, 2024

Hello, @Pears Whims 
I've tried both approaches but without success.
For the first one the error thrown is simple. It basically says "strftime()" not supported

The second approach throws an enormous error message describing where the query failed at the source: 
Error running query:
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 90737.0 failed 4 times:
java.util.IllegalFormatConversionException: d != java.lang.Double at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4302) at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2793)

Basically issues casting into integer.

Thanks in advance!
Best regards,
João



 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events