【问题标题】:How to specify the timestamp format when creating a table using a hdfs directory使用hdfs目录创建表时如何指定时间戳格式
【发布时间】:2018-10-24 20:39:10
【问题描述】:

我的 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 格式,以便正确解析时间戳?

【问题讨论】:

    标签: hadoop hive hdfs cloudera impala


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 2020-08-24
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多