我在 HDFS 上有一些数据,我正在尝试将其设置为通过配置单元查询。数据采用逗号分隔的文本文件形式。文件中的其中一列是日期/时间列,如下所示:
Wed Aug 29 16:16:58 CDT 2018
当我尝试读取使用以下脚本创建的 Hive 表时,我得到 NULL 作为正在为该列读取的值。
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 支持的适当日期格式...
最佳答案
从 Hive 1.2 开始,您可以像这样设置日期格式。
ALTER TABLE ORDERS SET SERDEPROPERTIES ("timestamp.formats"="EEE MMM dd HH:mm:ss zzz yyyy");
来自文档。
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.
关于date - Hive 日期/时间戳列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52502021/