Athena Presto SQLメモ(随時更新)


はじめに

Athenaで日付を扱う場合は、元データの形式がJavaのTIMESTAMP形式が必須なので、違う形式の場合はsql側で処理する必要がある。

Amazon Athena のテーブルにクエリを実行すると、TIMESTAMP の結果が空になる

iso8601形式の文字列をtimestamp型に変更

from_iso8601_timestamp(started_at)

経過時間(秒)を計算

date_diff('second', from_iso8601_timestamp(started_at), from_iso8601_timestamp(completed_at)) 

date_diff(unit, timestamp1, timestamp2) → bigint
Returns timestamp2 - timestamp1 expressed in terms of unit.

返り値の肩はbigint

経過時間を分に切り上げる

CEILING(cast(duration as DOUBLE) / 60)