1 Criar uma tabela de sub-barril: um pequeno arquivo para dividir um arquivo grande para alça
mesa pontos balde é também um tipo de consulta otimização projetado. Quando você cria uma lista de sub-balde, especificar o número de baldes e baldes de base sub-campo, Hive pode dividir automaticamente os barris de armazenamento de dados. Apenas precisa de dados de consulta atravessando um balde, ou atravessar a porção do barril, melhorando assim a eficiência da consulta.
A essência do barril é dividido em diferentes arquivos de dados. Reduzir a banheira e o mesmo número de pontos no no Hadoop Hive.
O papel da tabela sub-barril: 1. Melhorar a consulta aumento da eficiência amostragem eficiência 2. 3. melhorar a eficiência da junção
pontos barril principais: a colmeia é um único arquivo de dados, os dados divididos em tamanho uniforme
create table 分桶表的表名 ( 字段名1 数据类型,字段名 2 数据类型2 , .... )
clustered by ( 分桶字段 ) into 分桶的个数 buckets
row format delimited
fields terminated by '\001' --指定字段分隔符
collection items terminated by '\002' -- 指字集合的分隔符
map keys terminated by '\003' --指定map的分隔符
lines terminated by '\n' --指定行的分隔符
Nota: Campo de sub-barril deve ser na tabela de campo deve
create table students_bucket ( id string, name string, age int )
clustered by ( id ) sorted by ( id asc ) into 4 buckets
create table students_bucket ( id string, name string, java float,c float,oracle float,hadoop float ,sex string )
clustered by ( id ) sorted by ( id asc ) into 4 buckets
row format delimited
fields terminated by ',' ; --指定字段分隔符
insert into students_bucket select id,name,java,c, mysql as oracle,hadoop,sex from students;
-- 分桶只能使用insert 方法来执行MR程序 进行分桶 不能使用load data
load data local inpath '/home/zx/data/students2.csv' overwrite into table students_bucket
2 automático barril:
-1.原始数据表
create table students1(
id string,
name string,
score1 float,
score2 float,
score3 float,
score float
)row format delimited
fields terminated by ',';
--2.加载数据
load data local inpath '/home/sheng/data/students.csv' into table students1;
--3.创建分桶表
create table students_bucket1 (
id string,
name string,
score1 float,
score2 float,
score3 float,
score float
)
clustered by ( id ) sorted by ( score asc ) into 4 buckets
row format delimited
fields terminated by ','
--4.设置自动分桶开关
set hive.enforce.bucketing=true;
--4*把原始数据插入到分桶表中,并自动进行分桶
insert overwrite table students_bucket1 select * from students1;
pontos de amostragem barril
* De students_bucket1 SELECCIONAR
TABLESAMPLE (balde 4 ON do OUT um ID..);
. 3, a porção exterior da mesa de barril
create EXTERNAL table students_external_bucket (
id string,
name string,
java float,
c float,
mysql float,
hadoop float,
sex string
)
clustered by ( id ) sorted by ( id asc ) into 4 buckets
row format delimited
fields terminated by ','
LOCATION '/user/zx/bucket';
insert into students_external_bucket select * from students;
4 lista balde sub-distrito
create table students_p_b (
id string,
name string,
java float,
c float,
mysql float,
hadoop float
)
PARTITIONED BY (
sex string
)
clustered by ( id ) sorted by ( id asc ) into 4 buckets
row format delimited
fields terminated by ','
insert into students_p_b partition( sex ) select id,name,java,c,mysql , hadoop ,if ( sex='男','man','woman') as sex from students;