如何使用列类型 Timestamp 创建外部 Hive 表 [英] How to create an external Hive table with column typed Timestamp

查看:38
本文介绍了如何使用列类型 Timestamp 创建外部 Hive 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 HDFS 中包含 epoch 的文本文件创建一个外部 Hive 表.假设该文件位于 /user/me/test.txt.这是文件内容:

I want to create an external Hive table from a text file containing epoch in HDFS. Let's say the file is located at the /user/me/test.txt. Here's the file content:

1354183921
1354183922

我已经安装了 Hive 0.8.1 并且应该能够使用类型 Timestamp,所以我创建了表:

I have Hive 0.8.1 installed and should be able to use type Timestamp, so I created the table:

hive> CREATE EXTERNAL TABLE test1 (epoch Timestamp)
      LOCATION '/user/me';

然后我查询了表:

SELECT * FROM test1;

并得到以下异常:

Failed with exception java.io.IOException:java.lang.IllegalArgumentException: 
Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]

我在创建外部表时是否遗漏了什么?我很困惑,因为 Hive(从 0.8 开始)在第二个支持 Unix 纪元格式的时间戳:https://cwiki.apache.org/Hive/languagemanual-types.html#LanguageManualTypes-Timestamps

Have I missed anything when creating the external table? I'm confused because Hive (since 0.8) supports Timestamp in the format of Unix epoch in second: https://cwiki.apache.org/Hive/languagemanual-types.html#LanguageManualTypes-Timestamps

推荐答案

Timestamp 字符串必须采用错误消息和链接中指定的格式,yyyy-mm-dd hh:mm:ss[.fffffffff].要使用包含 epoch 的数据,您必须定义为 BIGINT,然后使用内置 UDF from_unixtime() 转换为表示日期的字符串.然后您可以使用其他 内置 UDF 日期函数操纵这个日期.

The Timestamp string must be in the format specified in the error message and link, yyyy-mm-dd hh:mm:ss[.fffffffff]. To use data that contains epoch, you would have to define as a BIGINT and then use the built-in UDF, from_unixtime() to convert to a string representing the date. Then you could use the other built-in UDF date functions to manipulate this date.

这篇关于如何使用列类型 Timestamp 创建外部 Hive 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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