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

标签 date amazon-athena presto

我希望在 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/

相关文章:

ios - 在 IOS 中手动设置日期值并使用日期选择器

Java:将字符串日期转换为月份名称年份 (MMM yyyy)

sql - PrestoDB : select all dates between two dates

Java 微服务无法与 AWS Athena 客户端通信 : Handshake_Failure

sql - 将 Athena SQL 与正则表达式结合使用

sql - LIKE 条件中的多个字符串 - Presto SQL

json - 有没有办法在 AWS Athena 中展平结构字段?

c - 打印当前日期

javascript - 如何强制 d3 的日期轴绘制未满的第一个月和最后一个月的刻度线[FIDDLE UPDATED]?

aws-cloudformation - Cloudformation 创建加密的 athena 粘合表