最近在公司实习,对hive进行了学习,做了些整理的笔记。 基础命令 show databases; # 查看某个数据库 use 数据库; # 进入某个数据库 show tables; # 展示所有表 desc 表名; # 显示表结构 show partitions 表名; # 显示表名的分区 show create table_name; # 显示创建表的结构 # 建表语句 # 内部表 use xxdb; create table xxx; # 创建一个表,结构与其他一样 create table xxx like xxx; # 外部表 use xxdb; create external table xxx; # 分区表 use xxdb; create external table xxx (l int) partitoned by (d string) # 内外部表转化 alter table table_name set TBLPROPROTIES ('EXTERNAL'='TRUE'); # 内部表转外部表 alter table table_name set TBLPROPROTIES ('EXTERNAL'='FALSE');# 外部表转内部表 # 表结构修改 # 重命名表 use xxxdb; alter table table_name rename to new_table_name; # 增加字段 alter table table_name add columns (newcol1 int comment ‘新增’); # 修改字段 alter table table_name change col_name new_col_name new_type; # 删除字段(COLUMNS中只放保留的字段) alter table table_name replace columns (col1 int,col2 string,col3 string); # 删除表 use xxxdb; drop table table_name; # 删除分区 # 注意:若是外部表,则还需要删除文件(hadoop fs -rm -r -f hdfspath) alter table table_name drop if exists partitions (d=‘2016-07-01'); # 字段类型 # tinyint, smallint, int, bigint, float, decimal, boolean, string # 复合数据类型 # struct, array, map
use mid ;
查询表
show tables;
查询表结构
desc mid_signaling_list;
删除表:
drop table if exists tishu.mid_signaling_list_tmp;
添加字段
alter table tishu.mid_signaling_list_tmp add columns(ci_name string);
删除字段
alter table tishu.mid_signaling_list_tmp REPLACE columns(ptime string);
删除分区字段
alter table tishu.mid_signaling_list_tmp DROP IF EXISTS PARTITION (ptime='01');
清空外部表
alter table tishu.mid_signaling_list_tmp drop if exists partition (pdate='20190101');
在Hive的外部表中不能truncate table,否则会直接报错。
比如: hive> truncate table test_01;
FAILED: SemanticException [Error 10146]:
Cannot truncate non-managed table test_01.
hive删除数据、删除分区、删除库表
-- 删除库
drop database if exists db_name;
-- 强制删除库
drop database if exists db_name cascade;
- 粉丝: 0
- 资源: 2
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助