查询hive sql 结果保存hdfs 或者本地操作如下

查询hive sql 结果保存hdfs 或者本地操作如下

一、保存到本地

insert overwrite local directory "/tmp/zhuqinghua" 

select user, login_time from user_login;

select userid ,count(*), num from bi.test where date_time = '2018-01-01' group by date_time,userid order by num desc limit 10;

二、保存到hdfs

insert overwrite  directory "/tmp/mtdata/trans/201810/" ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

SELECT month,md5(mobileno),count(userid) from bi.trans_monthly_detail_i_m where month='201810' group by month, mobileno, userid;

 

############################################

 

hive>create database database_name; 创建数据库

 

hive>creat database if not exists database_name

hive> show databases;   查看数据库

hive> show databases like 'h.*'; 如果数据库比较多的话,也可以用正则表达式来查看:

hive> use default;    --使用哪个数据库

hive>show tables;  --查看该数据库中的所有表

hive>show tables  ‘*t*’;    --支持模糊查询

hive> describe tab_name;    --查看表的结构及表的路径

hive> describe database database_name;  --查看数据库的描述及路径

hive> drop database if exists database_name; --删除空的数据库

hive> drop database if exists database_name cascade; --先删除数据库中的表再删

hive>show partitions t1;   --查看表有哪些分区 

hive>alter table table_name rename to another_name;   --修改表名

hive>drop table t1 ;      --删除表t1

hive> drop table if exists t1;

hive不支持修改表中数据,但是可以修改表结构,而不影响数据

有local的速度明显比没有local慢:

hive>load data inpath '/root/inner_table.dat' into table t1;   移动hdfs中数据到t1表中

 

hive>load  data local inpath '/root/inner_table.dat' into table t1;  上传本地数据到hdfs中

load data local inpath '${env:HOME}/目录' overwrite into table table_name partition (分区);

 

创建表ORC压缩存储

create table if not exists record_orc ( rid STRING,

uid STRING,

bid STRING,

price INT,

source_province STRING, target_province STRING, site STRING, express_number STRING, express_company STRING, trancation_date DATE

)

stored as orc;

insert into table record_orc select * from record;

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值