我希望在 Amazon Athena 中获得结果,我可以计算按天(或按月)创建的用户数量
但在此之前,我必须将 unix 时间戳转换为另一种日期格式。这就是我失败的地方。
我的最后一个目标是转换这种类型的时间戳:
1531888605109
在类似:
2018-07-18
According to Epoch Converter
但是当我尝试应用我在这个问题中看到的解决方案时:Casting unix time to date in Presto
我得到了错误:
[Simba]AthenaJDBC An error has been thrown from the AWS Athena client. SYNTAX_ERROR: line 1:13: Unexpected parameters (varchar) for function from_unixtime. Expected: from_unixtime(double) , from_unixtime(double, bigint, bigint) , from_unixtime(double, varchar(x)) [SQL State=HY000, DB Errorcode=100071]
这是我的查询:
select cast(from_unixtime(created)as date) as date_creation,
count(created)
from datalake.test
group by date_creation
也许我必须转换 scstring,因为该字段的数据类型不是日期。
我的表描述:Link to the table description
最佳答案
line 1:13: Unexpected parameters (varchar) for function from_unixtime. Expected: from_unixtime(double)
这意味着您的时间戳——即使它们显示为数字——是
varchar
s。您需要将 CAST 添加到
cast(from_unixtime(created)as date)
, 喜欢:CAST(from_unixtime(CAST(created AS bigint)) AS date)
注意:处理与时间相关的数据时,请记住https://github.com/prestosql/presto/issues/37在 Presto 中尚未解决。
关于date - 将字符串类型转换为 Unix 日期 Amazon Athena,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52923440/