HIVE 第七章 数据导入
Posted 麦田里的守望者
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HIVE 第七章 数据导入相关的知识,希望对你有一定的参考价值。
公告:更新任在持续,更多精彩内容敬请关注!
创建分区表
create table if not exists t_user( name string comment 'this is name', salary float comment 'salary of user', subordinates array<string> comment 'names of suordinates', deductions map<string,float> comment 'names>percentage' )comment 'user table' partitioned by (country string,state string) row format delimited fields terminated by ',' collection items terminated by '|' map keys terminated by '>' lines terminated by '\n' stored as textfile location '/hive/database/baizhi.db/t_user' tblproperties ('creator'='jiangzz')
构造数据
u1,15000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1 u2,10000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1 u3,8000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1 u4,9000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1
将该数据上传到本地/root/userData_cn目录下。
u5,15000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1 u6,10000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1 u7,8000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1 u8,9000,zhangsan|lisi|wangwu,Salray Taxes>0.25|Shopping Taxes>0.1
将该数据上传到本地/root/userData_us目录下。
上传数据
hive>load data local inpath '/root/userData_cn'
>overwrite into table
>t_user partition(country='china',state='beijing');
hive>load data local inpath '/root/userData_us'
>overwrite into table
>t_user partition(country='china',state='shanghai');
查询数据
hive> set hive.cli.print.header=true;
hive> select name,salary,country,state from t_user order by salary desc ;
name salary country state
u5 15000.0 china shanghai
u1 15000.0 china beijing
u6 10000.0 china shanghai
u2 10000.0 china beijing
u8 9000.0 china shanghai
u4 9000.0 china beijing
u7 8000.0 china shanghai
u3 8000.0 china beijing
Time taken: 32.337 seconds, Fetched: 8 row(s)
本期内容暂时更新到此,更多精彩内容请持续关注jiangzz_wy公众账号,如有任何疑问也可以添加小编jiangzz_wx微信。
以上是关于HIVE 第七章 数据导入的主要内容,如果未能解决你的问题,请参考以下文章