欢迎投稿

今日深度:

Hive表分区,

Hive表分区,


新建一个有一个分区dt的表baseinfo。

hive> create table baseinfo(
    > id int,
    > name string
    > )partitioned by (dt string) row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile; 
OK
Time taken: 0.132 seconds

在linux下面建立一个文件/baseinfo.txt,文件内容为

1    qiu

2    liu

将文件中的内容导入baseinfo表中,设置分区的值为当前日期'2014-03-03'。

hive> load data local inpath '/baseinfo.txt' overwrite into table baseinfo partition(dt = '2014-03-03');
Copying data from file:/baseinfo.txt
Copying file: file:/baseinfo.txt
Loading data to table hbmsdb.baseinfo partition (dt=2014-03-03)
Deleted hdfs://hadoop00:9000/user/hive/warehous/hbmsdb.db/baseinfo/dt=2014-03-03
OK
Time taken: 0.442 seconds

在linux下面建立一个文件/baseinfo2.txt,文件内容为

3 zheng

4 yang

将文件中的内容导入baseinfo表中,设置分区的值为当期日期‘2014-03-04’。

hive> load data local inpath '/baseinfo.txt' overwrite into table baseinfo partition(dt = '2014-03-04');                                                      
Copying data from file:/baseinfo.txt
Copying file: file:/baseinfo.txt
Loading data to table hbmsdb.baseinfo partition (dt=2014-03-04)
OK
Time taken: 0.189 seconds

查看分区

hive> show partitions baseinfo;                                                                         
OK
dt=2014-03-03
dt=2014-03-04
Time taken: 0.054 seconds

 查看数据

hive> select * from baseinfo;
OK
1       qiu     2014-03-03
2       liu     2014-03-03
3       zheng   2014-03-04
4       yang    2014-03-04
Time taken: 0.141 seconds
hive> select * from baseinfo where dt = '2014-03-03';
OK
1       qiu    2014-03-03
2       liu    2014-03-03
Time taken: 0.149 seconds


通过查询将内容保存在本地文件系统上

hive> insert overwrite  local directory '/home/hive' select * from baseinfo;

www.htsjk.Com true http://www.htsjk.com/hive/36775.html NewsArticle Hive表分区, 新建一个有一个分区dt的表baseinfo。 hive create table baseinfo( id int, name string )partitioned by (dt string) row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile; OKTime t...
相关文章
    暂无相关文章
评论暂时关闭