在配置单元表中创建具有日期数据类型的列

ash*_*ini 5 timestamp hive date

我使用值在HIVE(0.10.0)中创建了表:

2012-01-11  17:51   Stockton    Children's Clothing     168.68  Cash
2012-01-11  17:51   Tampa       Health and Beauty       441.08  Amex
............
Run Code Online (Sandbox Code Playgroud)

这里的日期和时间是制表符分隔的值,我需要在日期列上工作,由于Hive不允许使用“日期”数据类型,因此我在第一个日期列中使用了“ TIMESTAMP”(2012-01-11,...),但是,在创建表之后,它在第一列中显示NULL值。

如何解决呢?请指导。

vis*_*akh 5

我将数据加载到表中所有列均定义为的表中string,然后转换日期值并加载到该表中定义为的另一个表中DATE。似乎没有任何问题。唯一的区别是我使用的是Shark版本的Hive,老实说,我不确定实际的Hive和Shark Hive是否存在任何重大差异。

数据:

hduser2@ws-25:~$ more test.txt 
2010-01-05  17:51   Visakh
2013-02-16  09:31   Nair
Run Code Online (Sandbox Code Playgroud)

码:

[localhost:12345] shark>  create table test_time(dt string, tm string, nm string) row format delimited fields terminated by '\t' stored as textfile;
Time taken (including network latency): 0.089 seconds
[localhost:12345] shark> describe test_time;
dt  string  
tm  string  
nm  string  
Time taken (including network latency): 0.06 seconds
[localhost:12345] shark> load data local inpath '/home/hduser2/test.txt' overwrite into table test_time;                                                   
Time taken (including network latency): 0.124 seconds
[localhost:12345] shark> select * from test_time;
2010-01-05  17:51   Visakh
2013-02-16  09:31   Nair
Time taken (including network latency): 0.397 seconds
[localhost:12345] shark> select cast(dt as date) from test_time;
2010-01-05
2013-02-16
Time taken (including network latency): 0.399 seconds
[localhost:12345] shark> create table test_date as select cast(dt as date) from test_time;
Time taken (including network latency): 0.71 seconds
[localhost:12345] shark> select * from test_date;
2010-01-05
2013-02-16
Time taken (including network latency): 0.366 seconds
[localhost:12345] shark> 
Run Code Online (Sandbox Code Playgroud)

如果您使用TIMESTAMP,则可以尝试将日期和时间字符串串联起来然后进行强制转换。

create table test_1 as select cast(concat(dt,' ', tm,':00') as string) as ts from test_time;

select cast(ts as timestamp) from test_1;
Run Code Online (Sandbox Code Playgroud)