配置单元日期/时间戳列 [英] Hive date/timestamp column

查看:149
本文介绍了配置单元日期/时间戳列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些试图通过配置单元查询的HDFS数据。数据采用逗号分隔的文本文件的形式。文件中的列之一是日期/时间列,如下所示:

I have some data on HDFS that I am trying to setup to be queried via hive. The data is in the form of comma separated text files. One of the columns in the file is the date/time column as follows:

Wed Aug 29 16:16:58 CDT 2018

当我尝试读取使用以下脚本创建的Hive表时,得到的值为NULL

When I try to read the Hive table created using the following script, I get NULL as the value being read for this column..

use test_db;
drop table ORDERS;

create external table ORDERS(
    SAMPLE_DT_TM TIMESTAMP
    ...
)
row format delimited
fields terminated by ',' 
stored as textfile
location '/user/data';

当我用STRING替换TIMESTAMP时,我能够读取列值。但不确定如何将其读取为Hive支持的适当日期格式...

When I replace TIMESTAMP by STRING, I am able to read the column value. But not sure how to read it as an appropriate date format supported by Hive...

推荐答案

在Hive 1.2中,您可以设置您的日期格式是这样的。

From Hive 1.2, you can set your date format like this.

ALTER TABLE ORDERS SET SERDEPROPERTIES ("timestamp.formats"="EEE MMM dd HH:mm:ss zzz yyyy");

来自文档。


在表级别,
可以为SerDe属性 timestamp.formats提供格式,以支持其他时间戳格式。 (从
用HIVE-9298发布1.2.0起)。例如,
yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd'T'HH:mm:ss。

On the table level, alternative timestamp formats can be supported by providing the format to the SerDe property "timestamp.formats" (as of release 1.2.0 with HIVE-9298). For example, yyyy-MM-dd'T'HH:mm:ss.SSS,yyyy-MM-dd'T'HH:mm:ss.

这篇关于配置单元日期/时间戳列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆