我是靠谱客的博主 粗暴棒棒糖,这篇文章主要介绍hive中建表及put数据,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
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 '01' lines terminated by 'n stored as textfile location '/user/hive/warehouse/orders.db/order/';

说明:

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

comment 表示对表的说明。

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

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

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中数据列与列之间要用建表时指定的01分隔,并且列的顺序严格按照建表时列的顺序(addr_id,prod_name,allot_quantity)存放。

最后

以上就是粗暴棒棒糖最近收集整理的关于hive中建表及put数据的全部内容,更多相关hive中建表及put数据内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(85)

评论列表共有 0 条评论

立即
投稿
返回
顶部