带时区的Athena表时间戳不可能



我正在尝试创建一个具有时区信息的时间戳列的athena表。create-sql看起来像这样:

CREATE EXTERNAL TABLE `tmp_123` (
`event_datehour_tz` timestamp with time zone
)
ROW FORMAT SERDE 
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT 
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
's3://...'
TBLPROPERTIES (
'Classification'='parquet'
)

当我运行这个时,我得到错误:

第1:8行:不匹配的输入"外部"。应为:"or"、"schema"、"table"、"view"(服务:amazonatha;状态代码:400;错误代码:invalidrequestexception;请求id:b7fa4045-777e-4151-84d7-1b43db2b68f2;代理:null(

如果我删除with time zone,它将创建表。我试过这个和timestamptz。难道不能在athena中创建一个具有timestamp with time zone列的表吗?

不幸的是,Athena不支持带时区的时间戳。

您可以在该函数调用周围使用CAST()函数,这将把类型从timestamp with time zone更改为timestamp

或者,您可以将其保存为timestamp,并使用下面给出的AT TIME STAMP运算符:

SELECT event_datehour_tz AT TIME ZONE 'America/Los_Angeles' AS la_time;

只是在@AswinRajaram回答Athena不支持带时区的时间戳后给出一个完整的解决方案。以下是如何从字符串中CAST时间戳并将其与时区一起使用。

select 
parse_datetime('2022-09-10_00', 'yyyy-MM-dd_H'),
parse_datetime('2022-09-10_00', 'yyyy-MM-dd_H') AT TIME ZONE 'Europe/Berlin',
at_timezone(CAST(parse_datetime('2022-09-10_00', 'yyyy-MM-dd_HH') AS timestamp), 'Europe/Berlin') AS date_partition_berlin,
CAST(parse_datetime('2022-09-10_00', 'yyyy-MM-dd_HH') AT TIME ZONE 'Europe/Berlin' AS timestamp) AS date_partition_timestamp;
2022-09-10 00:00:00.000 UTC
2022-09-10 02:00:00.000 Europe/Berlin // time zone conversion + 2 hours
2022-09-10 02:00:00.000 Europe/Berlin // time zone conversion + 2 hours
2022-09-10 00:00:00.000

最新更新