hive 新建表、新增一行记录、复制表



#创建一个表
create table if not exists xjj_tab(
id string,
name string,
tel string comment '电话'
)
row format delimited fields terminated by '|'
stored as textfile;
#上传文件到hdfs
hadoop fs -put /home/bdp/xjj/hh.txt /user/hive/warehouse/hive_miguc.db/xjj_tab
#
#从另一个表中复制
insert into table xjj_tab
select * from xjj_rownum;

#创建一个数组表,explode 对数组进行转置
create table xjj_test(mycol array<int>);
insert overwrite table xjj_test
select array(1,2,3) union all select array(4,5,6);
select * from xjj_test;
SELECT explode(myCol) AS myNewCol FROM xjj_test;

#order by 与sort by
select * from xjj_tab
order by id,name;
select * from xjj_tab
sort by id,name;

#插入新的数据
##union all 连接一行还是一个表要注意区别 不会去除重复的数据
##union连接 去除重复的数据
insert overwrite table xjj_test
select * from (select a.* from xjj_test a
union all select array(70,80,90) as mycol from xjj_test b ) t ;

insert into table xjj_tab
select * from (select a.* from xjj_tab a
union all select 1 as id,'asd' as name,1234 as tel ) t;

insert into table xjj_test
select * from (select a.* from xjj_test a
union all select array(70,80,90) as mycol ) t;


create table tablename(
id string comment '学号',
name string,
department string,
grade array<int> comment '各科成绩汇总'
)
row format delimited fields terminated by '|'
stored as textfile


insert into table xjj_test
select * from (select a.* from xjj_test a
union all select array(7000,8000,9000) as mycol from xjj_test b) t;

insert into table xjj_test
select * from (select a.* from xjj_test a
union all select array(70000,80000,90000) as mycol ) t; ##在最后追加一条记录。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM