Hive的分桶表

147 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第31天,10月更文诚意加码,激发写作潜力|掘金·日新计划 - 掘金 (juejin.cn)点击查看活动详情

二、Hive的分桶表

1、创建分桶表

首先要进入hive里面 在虚拟机里输入 beeline -u 'jdbc:hive2://192.168.67.110:10000' -n root

然后使用库

use abd(库名);

再创建表

create table student_bck(id int, name string)

clustered by (id) into 3 buckets #3个桶

row format delimited fields terminated by ",";

image.png

2、向桶中插入数据

insert overwrite table student_bck

select id,name from student;

image.png

3、查看分桶数据

select * from student_bck tablesample(bucket 1 out of 3 on id);

image.png

select * from student_bck tablesample(bucket 2 out of 3 on id);

image.png

select * from student_bck tablesample(bucket 3 out of 3 on id);

image.png

查看存储信息

image.png

tablesample (bucket x out of y on id);

x表示从哪个桶(x-1)开始,y代表分几个桶,也可以理解分x为分子,y为分母,即将表分为y份(桶),取第x份(桶)。

视图

1.数据准备

一样,use 库然后,在node01里填写数据

vi new_test.txt 填入数据 再在hive里创建new_test表格

create table new_test(id int, name string,age string,new_addr string,score string)

row format delimited fields terminated by ",";

再导入数据

load data local inpath ‘/opt/software/testData/hive/new_test.txt’ overwrite into table new_test;

有overwrite意思是覆盖数据,没有重复数据,但是没有就是叠加数据。

然后select * from new_test; image.png

2、创建视图:

create view v_name

as

select name,age from new_test;

image.png