gpt4 book ai didi

function - 如何将unix纪元时间转换为hive中的日期字符串

转载 作者:行者123 更新时间:2023-12-02 15:33:17 24 4
gpt4 key购买 nike

我有一个包含时间戳列的日志文件。时间戳采用 unix 纪元时间格式。

我想根据时间戳创建一个分区,其中包含年、月和日分区。

到目前为止,我已经做到了这一点,但它抛出了一个错误。

PARSE ERROR cannot recognize input '(' in column type

这是我的代码。

from (
from raw_data
MAP ${PREFIX}raw_data.line
USING 's3://scripts/clean.py'
AS (timestamp STRING, name STRING)
) map_out
INSERT OVERWRITE TABLE date_base_data_temp PARTITION(year(timestamp), month(timestamp)), day(timestamp)))
select map_out.name;

最佳答案

哦,看起来很丑。尝试在 Hive 中使用此函数:

SELECT from_unixtime(unix_timestamp) as new_timestamp from raw_data ...

或者如果时间戳的单位是ms而不是秒:

SELECT from_unixtime(unix_timestamp DIV 1000) as new_timestamp from raw_data ...

它将unix时间戳转换为YYYY-MM-DD HH:MM:SS格式,然后您可以使用以下函数获取年、月和日:

SELECT year(new_timestamp) as year, month(new_timestamp) as month, day(new_timestamp) as day ...

关于function - 如何将unix纪元时间转换为hive中的日期字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7211224/

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