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

yvgpqqbh  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(436)

我有以下csv文件位于 path/to/file 在我的hdfs商店里。

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

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

  1. create external table t
  2. (
  3. number string,
  4. reported_time timestamp
  5. )
  6. ROW FORMAT delimited fields terminated BY ','
  7. LOCATION 'path/to/file';

我可以在impala查询编辑器中看到 reported_time 表中的列 t 始终为空。我想这是因为我的时间戳不是公认的时间戳格式。
问题:
如何指定timestamp列应为 dd/mm/yyyy hh:min 格式化以便正确解析时间戳?

czfnxgou

czfnxgou1#

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

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

相关问题