gpt4 book ai didi

hadoop - 使用hdfs目录建表时如何指定时间戳格式

转载 作者:可可西里 更新时间:2023-11-01 15:50:18 28 4
gpt4 key购买 nike

我的 hdfs 存储中的 path/to/file 中有以下 csv 文件。

1842,10/1/2017 0:02
7424,10/1/2017 4:06

我正在尝试使用以下命令创建一个表:

create external table t
(
number string,
reported_time timestamp
)
ROW FORMAT delimited fields terminated BY ','
LOCATION 'path/to/file';

我可以在 impala 查询编辑器中看到 t 表中的 reported_time 列始终为空。我想这是因为我的时间戳不是可接受的时间戳格式。

问题:

如何指定时间戳列应为 dd/mm/yyyy hh:min 格式,以便正确解析时间戳?

最佳答案

您不能自定义时间戳(根据我的 exp*),但您可以创建具有字符串数据类型的表,然后您可以将字符串转换为时间戳,如下所示:

select number,
reported_time,
from_unixtime(unix_timestamp(reported_time),'dd/MM/yyyy HH:mm') as reported_time
from t;

关于hadoop - 使用hdfs目录建表时如何指定时间戳格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50342969/

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