第18天: hive数据加载 从文件加载到hive表讲解和案例操作、从查询插入数据到hive表讲解和案例操作

来源:互联网 发布:青鸟华光超捷排版软件 编辑:程序博客网 时间:2024/06/14 21:41
Hive学习实战   
--------------------------------------------------------------
Hive从入门到实战【40讲】---笔记记录
--------------------------------------------------------------
 
hive命令
1、show tables;
2、show databases;
3、 desc login; ---查看表结构。
4、 show partitions test5; --查看分区


第18天:  hive数据加载  从文件加载到hive表讲解和案例操作、从查询插入数据到hive表讲解和案例操作


insert overwrite table tablname1 [partition ]
if not existes   select_statement1 from statement;


从别的表查询,插入到其他表中。


从查询插入数据到hive表
示例:
insert overwrite table login_user  select destinct uid from
login_log  
从登录日志表查询登录用户
插入到表login_user中,如果login_user以有数据,则覆盖,
否则创建


insert overwrite table  login user partiton(dt=..)
selct  ...




create table login_user(
  uid string 
  
)
partitioned by (dt string)
 
stored as textfile; 




insert overwrite table  login_user
partition(dt='20150207') 
select distinct uid from login where dt='20150207'








create table userinfo(
  id int,
  name string
)
 
row format delimited
fields terminated by ','
stored as textfile; 
 
create table mutil1(
  id int,
  name string
 )
row format delimited
fields terminated by ','
stored as textfile; 


create table  mutil2(
  sumid int,
  name string

row format delimited
fields terminated by ','
stored as textfile; 


load data local inpath '/hadoop/hive0.9/testHive/userinfo.txt'
into table userinfo;


-------
同事插入两张表中。
------
from  userinfo
insert overwrite table mutil1  select id ,name
insert overwrite table mutil2 
select count(distinct id),name group by name;
0 0
原创粉丝点击