数仓--Hive--总结之Hive常用命令以及作用

本文详细介绍了Hive中各类SQL操作,包括表的创建、数据导入、表属性修改、列操作、表重命名、分区管理等核心功能,并提供了具体语法示例,帮助读者快速掌握Hive的数据管理和查询技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 1 . 创建表
-- 内部表
create table a1(col1 string,col2 int) partitioned by(statdate int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'-- 外部表
create external table b1(col1 string, col2 int) partitioned by(statdate int) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' location '/user/gaofei.lu/';
  • 2 . 查看创建表语句
show create table tablename;
  • 3 . 导入表数据
本地数据:load data local inpath ' /home/feifei/aa.txt' into table aa partition(statdate=20180315)
hdfs上数据:load data inpath '/user/feifei/aa.txt' into table bb partition(statdate=20180315)
  • 4-修改表属性
alter table aa set tblproperties ('EXTERNAL'='TRUE')
alter table bb set tblproperties ('EXTERNAL'='FALSE')
  • 5 . 修改列
修改列名和列数据类型:alter table aa change col2 name string ;
修改位置放置第一位:alter table aa change col2 name string first;
修改位置指定某一列后面:alter table aa change col1 dept string after name;
  • 6 . 添加列(慎用)
alter table aa add columns(col3 string);
  • 7 . 表重命名
alter table aa rename to aa_test;
  • 8 . 添加分区
alter table aa add partition(statdate=20180315);
alter table bb add partition(statdate=20180315) location '/user/gaofei.lu/20180315.txt';
  • 9 . 查看表分区
show partitioins aa;
  • 10 . 修改分区
alter table aa partition(statdate=20180315) rename to partition(statdate=20180316);
alter table bb partition(statdate=20180315) set location '/user/gaofei.lu/aa.txt';
  • 11 . 删除分区
alter table aa drop if exists partition(statdate=20180315);
  • 12 . beeline连接
beeline  !connect jdbc:hive2://192.168.1.01:10000
  • 13 . 设置hive on spark
set hive.execution.engine=spark
  • 14 . 终止任务
yarn application -kill job_id
  • 15 . 指定分隔符导出文件
insert overwrite local directory '/home/hadoop/gaofeilu/test_delimited.txt'
row format delimited
fields terminated by '\t'
select * from test;

推荐博客 : 数仓–Hive–总结之Hive架构原理

推荐博客 : 关于Hive的那些事

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值