【发布时间】:2017-11-15 22:34:28
【问题描述】:
这几天我没能找到这个。
如果我的配置单元表中数据的 avro 架构是:
{
"type" : "record",
"name" : "messages",
"namespace" : "com.company.messages",
"fields" : [ {
"name" : "timeStamp",
"type" : "long",
"logicalType" : "timestamp-millis"
}, {
…
我使用 presto 来查询这个,我没有得到格式化的时间戳。
select "timestamp", typeof("timestamp") as type,
current_timestamp as "current_timestamp", typeof(current_timestamp) as current_type
from db.messages limit 1
timestamp type current_timestamp current_type 1497210701839 bigint 2017-06-14 09:32:43.098 Asia/Seoul timestamp with time zone
我认为将它们转换为毫秒精度的时间戳不会有问题,但我发现我没有明确的方法来做到这一点。
select cast("timestamp" as timestamp) from db.messages limit 1
line 1:16: Cannot cast bigint to timestamp
他们还更改了 presto 的时间戳转换以始终假定源以秒为单位。 https://issues.apache.org/jira/browse/HIVE-3454
所以如果我使用from_unixtime(),我必须减少毫秒,否则它会给我一个非常遥远的日期:
select from_unixtime("timestamp") as "timestamp" from db.messages limit 1
timestamp +49414-08-06 07:15:35.000
当然,经常使用 Presto 的其他人知道如何正确表达转换。 (顺便说一句,我无法重新启动 Presto 或 Hive 服务器以将时区强制为 UTC)。
【问题讨论】:
标签: presto