hive中建表及put数据

来源:互联网 发布:如何进行wifi网络认证 编辑:程序博客网 时间:2024/05/29 04:07

1.在hive中创建一张order表,语句如下:

create external table order(addr_id           bigint comment 'addr_id',prod_name    string,allot_quantity string)comment 'order'partitiononed by (create_date,order_type)row format delimited fields terminated by '\001'lines terminated by '\nstored as textfilelocation '/user/hive/warehouse/orders.db/order/';

说明:

external 表示创建一张外部表。创建外部表的好处是:a.将数据放在location所在的目录,通过hive可以直接查询数据。b.多个表可以共用一份数据,只需将多个表的location指向同一个目录。

comment 表示对表的说明。

partitioned by 建立分区表。分区表是将列值一样的数据放在同一个文件下,如果该文件夹下面还有子分区,还可以再分小文件夹。

row format 表示列与列之间通过\001分隔。

lines terminated 表示用\n分隔行

location 表示表中文件存放的hdfs目录

2.将/data目录下的数据文件order_today.txt放入表order中的命令为:

hadoop dfs -put /data/order_today.txt  /user/hive/warehouse/orders.db/order/

3.注意事项

a.建表的时候一定要先使用use 语句指定库。如 use orders; 否则会将表建到hive默认的库default中。

b.order_today.txt中数据列与列之间要用建表时指定的\001分隔,并且列的顺序严格按照建表时列的顺序(addr_id,prod_name,allot_quantity)存放。

0 0
原创粉丝点击