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