[英]Casting String type to Unix Date Amazon Athena
我希望在Amazon Athena上獲得一個結果,我可以算出按天(或按月)創建的用戶數量
但是之前,我必須將unix時間戳轉換為另一種日期格式。 這就是我失敗的地方。
我的最后一個目標是轉換這種類型的時間戳:
1531888605109
在類似:
2018-07-18
但是,當我嘗試應用該解決方案時,我在此問題中看到了: 在Presto中投放Unix時間
我得到了錯誤:
[Simba] AthenaJDBC AWS Athena客戶端引發了錯誤。 語法:錯誤的行1:13:函數from_unixtime的意外參數(varchar)。 預期:from_unixtime(double),from_unixtime(double,bigint,bigint),from_unixtime(double,varchar(x))[SQL狀態= HY000,DB錯誤代碼= 100071]
這是我的查詢:
select cast(from_unixtime(created)as date) as date_creation,
count(created)
from datalake.test
group by date_creation
也許我不得不放棄sctring,因為字段的數據類型不是日期。
我的表格說明: 鏈接到表格說明
第1:13行:函數from_unixtime的意外參數(varchar)。 預期:from_unixtime(double)
這意味着您的時間戳-即使它們顯示為數字-都是varchar
。 您需要向CAST cast(from_unixtime(created)as date)
添加一個CAST,例如:
CAST(from_unixtime(CAST(created AS bigint)) AS date)
注意:在處理與時間有關的數據時,請記住,Presto中尚未解析https://github.com/prestosql/presto/issues/37 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.