我正在放置在HDFS目录中的.txt文件上创建一个hive表。访问数据时,它会将最后一个datetime列(order_dtm)的输出显示为NULL。我已经搜索并尝试了谷歌提供的其他选项,但到目前为止还没有任何工作。
Hive查询:---制表符分隔
Create EXTERNAL table Orders(
order_id int,
cust_id int,
order_dtm TIMESTAMP)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION '/user/analyst/order/';
HDFS File -head
>> hdfs dfs -cat /user/analyst/order/orders.txt | head -10
17/09/15 23:46:37 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
5000001 1133938 06-01-2008 00:03:35
5000002 1131278 06-01-2008 00:27:42
5000003 1153459 06-01-2008 00:49:37
5000004 1159099 06-01-2008 01:05:28
5000005 1020687 06-01-2008 01:08:36
5000006 1187459 06-01-2008 01:11:09
5000007 1048773 06-01-2008 01:36:35
5000008 1064002 06-01-2008 01:36:52
5000009 1096744 06-01-2008 01:49:46
5000010 1107526 06-01-2008 03:07:14
cat: Unable to write to output stream.
答案 0 :(得分:1)
create external table orders
(
order_id int
,cust_id int
,order_dtm string
)
row format delimited
fields terminated by ' '
location '/user/analyst/order'
tblproperties ('serialization.last.column.takes.rest'='true')
;
select * from orders
;
+-----------+----------+----------------------+
| order_id | cust_id | order_dtm |
+-----------+----------+----------------------+
| 5000001 | 1133938 | 06-01-2008 00:03:35 |
| 5000002 | 1131278 | 06-01-2008 00:27:42 |
| 5000003 | 1153459 | 06-01-2008 00:49:37 |
| 5000004 | 1159099 | 06-01-2008 01:05:28 |
| 5000005 | 1020687 | 06-01-2008 01:08:36 |
| 5000006 | 1187459 | 06-01-2008 01:11:09 |
| 5000007 | 1048773 | 06-01-2008 01:36:35 |
| 5000008 | 1064002 | 06-01-2008 01:36:52 |
| 5000009 | 1096744 | 06-01-2008 01:49:46 |
| 5000010 | 1107526 | 06-01-2008 03:07:14 |
+-----------+----------+----------------------+
create view orders_v
as
select order_id
,cust_id
,from_unixtime(to_unix_timestamp(order_dtm,'MM-dd-yyyy HH:mm:ss')) as order_dtm
from orders
;
select * from orders_v
;
+-----------+----------+----------------------+
| order_id | cust_id | order_dtm |
+-----------+----------+----------------------+
| 5000001 | 1133938 | 2008-06-01 00:03:35 |
| 5000002 | 1131278 | 2008-06-01 00:27:42 |
| 5000003 | 1153459 | 2008-06-01 00:49:37 |
| 5000004 | 1159099 | 2008-06-01 01:05:28 |
| 5000005 | 1020687 | 2008-06-01 01:08:36 |
| 5000006 | 1187459 | 2008-06-01 01:11:09 |
| 5000007 | 1048773 | 2008-06-01 01:36:35 |
| 5000008 | 1064002 | 2008-06-01 01:36:52 |
| 5000009 | 1096744 | 2008-06-01 01:49:46 |
| 5000010 | 1107526 | 2008-06-01 03:07:14 |
+-----------+----------+----------------------+