没有合适的资源?快使用搜索试试~ 我知道了~
1.创建分区表语法 1.创建二级分区表 2.正常的加载数据 3.查询数据
资源详情
资源评论
资源推荐
Hive 基本操作
Hive 实际操作
(1)启动 hive
bin/hive
(2)查看数据库
hive> show databases;
(3)打开默认数据库
hive> use default;
(4)显示 default 数据库中的表
hive> show tables;
(5)创建一张表
hive> create table student(id int, name string);
(6)显示数据库中有几张表
hive> show tables;
(7)查看表的结构
hive> desc student;
(8)向表中插入数据
hive> insert into student values(1000,"ss");
(9)查询表中数据
hive> select * from student;
(10)退出 hive
hive> quit;
(1)启动 hive
bin/hive
(2)显示数据库
hive> show databases;
(3)使用 default 数据库
建表语句
显示数据库信息
显示数据库详细信息,extended
删除空数据库
如果删除的数据库不存在 ,最好采用 if exists 判断 数据库是否存在
hive> use default;
(4)显示 default 数据库中的表
hive> show tables;
(5)删除已创建的 student 表
hive> drop table student;
(6)创建 student 表, 并声明文件分隔符’\t’
hive> create table student(id int, name string) ROW FORMAT
DELIMITED FIELDS TERMINATED
BY '\t';
(7)加载/opt/module/data/student.txt 文件到 student 数据库表中。
hive> load data local inpath '/opt/module/data/student.txt' into table student;
create table test(
name string, friends array<string>, children map<string, int>, address
struct<street:string, city:string>
) row format delimited fields terminated by ',' collection items terminated by
'_' map keys terminated by ':'
lines terminated by '\n';
字段解释:
row format delimited fields terminated by ',' -- 列分隔符
collection items terminated by '_'
--MAP STRUCT 和 ARRAY 的分隔符(数据分割 符号)
map keys terminated by ':' -- MAP 中的 key 与 value 的分隔符
lines terminated by '\n'; -- 行分隔符
hive> desc database db_hive;
hive> desc database extended db_hive;
hive>drop database db_hive2;
如果数据库不为空,可以 采用 cascade 命令,强制删除
查看表格式化数据
管理表与外部表的互相转 换
分区表
分区表基本操作
hive> drop database db_hive;
hive> drop database if exists db_hive2;
hive> drop database db_hive cascade;
hive > desc formatted dept;
(1)查询表的类型
hive (default)> desc formatted student2;
(2)修改内部表 student2 为外部表
alter table student2 set tblproperties('EXTERNAL'='TRUE');
(3)查询表的类型
hive (default)> desc formatted student2;
(4)修改外部表 student2 为内部表
alter table student2 set tblproperties('EXTERNAL'='FALSE'); ( 括号内部要大写)
(5)查询表的类型
hive (default)> desc formatted student2;
1.创建分区表语法
hive (default)> create table dept_partition(
deptno int, dname string, loc string
)
partitioned by (month string)
row format delimited fields terminated by '\t';
2.加载数据到分区表中
hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table
default.dept_partition partition(month='201709');
hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table
default.dept_partition partition(month='201708');
hive (default)> load data local inpath '/opt/module/datas/dept.txt' into table
default.dept_partition partition(month='201707’);
3.查询分区表中数据
(1).单分区查询
剩余16页未读,继续阅读
莫少儒
- 粉丝: 25
- 资源: 311
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0