将字符串类型转换为 Unix 日期 Amazon Athena

Casting String type to Unix Date Amazon Athena

我希望在 Amazon Athena 中获得结果,我可以计算每天(或可能按月)创建的用户数量

但之前我必须将 unix 时间戳转换为另一种日期格式。这就是我失败的地方。

我的最后一个目标是转换这种类型的时间戳:

1531888605109

类似于:

2018-07-18

According to Epoch Converter

但是当我尝试应用我在这个问题中看到的解决方案时:

我收到错误:

[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

也许我必须强制转换字符串,因为该字段的数据类型不是日期。

我的table描述:Link to the table description

line 1:13: Unexpected parameters (varchar) for function from_unixtime. Expected: from_unixtime(double)

这意味着您的时间戳——即使它们显示为数字——是 varchar。 您需要将 CAST 添加到 cast(from_unixtime(created)as date),例如:

CAST(from_unixtime(CAST(created AS bigint)) AS date)

注意:在处理与时间相关的数据时,请注意 https://github.com/prestosql/presto/issues/37 尚未在 Presto 中解析。