查询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;