gpt4 book ai didi

python - AWS Athena 使用填充有错误数据的创建表从 Epoch 到时间戳的转换

转载 作者:行者123 更新时间:2023-12-02 02:07:36 25 4
gpt4 key购买 nike

我已使用单个 Parquet 文件加载 S3 以测试 Athena 查询。

将文件上传到 S3 后,我使用 S3 选择查询来检查数据。

示例:

Status
Successfully returned 5 records in 460 ms
Bytes returned: 3278 B
{
"test_date":1467936000
}

我使用这个 Parquet 文件通过以下查询创建表

CREATE EXTERNAL TABLE `test_table`(
`test_date` timestamp)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://xxxxxxxxx/'
TBLPROPERTIES (
'has_encrypted_data'='false')

当我查询表的时候,它给了我

    test_date
1 1970-01-17 23:45:36.000
2 1970-01-17 23:45:36.000
3 1970-01-17 23:45:36.000
etc.

但是使用 python 转换 parquet 文件中的原始整数,即 1467936000 给我正确的日期时间。

>datetime.datetime.fromtimestamp(1467936000)
datetime.datetime(2016, 7, 8, 5, 30)

如何让 Athena 将 Epoch 正确解释为时间戳?

最佳答案

显然 Athena 要求 Epoch 格式以毫秒为单位。我在 内得到了它。

在数据文件中乘以 1000 解决了我的问题。

例子:

1467936000000 正确转换为 2016-07-08 00:00:00.000

关于python - AWS Athena 使用填充有错误数据的创建表从 Epoch 到时间戳的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68193962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com