欢迎来到田晓东的博客

人生三从境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。
扩大
缩小

kudu 常用整理

进入终端,输入Impala-shell,进入impala数据库命令窗口

impala-shell

创建库:

create database kudu_test_txd;

kudu内部表:

create table multi_kudu_table3
(
id BIGINT,
name STRING,
mobile BIGINT,
info STRING,
created_time STRING,
address STRING,
PRIMARY KEY(id)
)
PARTITION BY HASH PARTITIONS 2 STORED AS KUDU;

格式化查看:

desc formatted multi_kudu_table3;

外部表:

create external table multi_table_external3
STORED AS KUDU
TBLPROPERTIES(
'kudu.master_addresses'='10.201.0.114,10.201.0.115,10.201.0.116',
'kudu.table_name'='impala::kudu_test_txd.multi_kudu_table3'
);

测试内外部表:

INSERT INTO multi_kudu_table3 VALUES (1,"xj",123,"xj","20210824","xj");
INSERT INTO multi_kudu_table3 VALUES (2,"xz",123,"xz","20210824","xz");
INSERT INTO multi_kudu_table3 VALUES (3,"gs",123,"gs","20210824","gs");
INSERT INTO multi_kudu_table3 VALUES (4,"nz",123,"nz","20210824","nz");
INSERT INTO multi_kudu_table3 VALUES (5,"xn",123,"xn","20210824","xn");
INSERT INTO multi_kudu_table3 VALUES (6,"lz",123,"lz","20210824","lz");
INSERT INTO multi_kudu_table3 VALUES (7,"nx",123,"nx","20210824","nx");
INSERT INTO multi_kudu_table3 VALUES (8,"nm",123,"nm","20210824","nm");

select * from multi_kudu_table3;

创建内部range分区表:

CREATE TABLE multi_partition_table1  
(  
id BIGINT,
year INT, 
name STRING,
mobile BIGINT,
info STRING,
created_time STRING,
address STRING,
PRIMARY KEY(id,year)

) PARTITION BY RANGE(year) (  
	PARTITION 2000 <= VALUES < 2005,  
	PARTITION 2005 <= VALUES < 2010,  
	PARTITION 2010 <= VALUES < 2015,  
	PARTITION 2015 <= VALUES < 2020  
) STORED AS KUDU;

创建Hash分区表:此分区字段需是第一个字段,单个

CREATE TABLE multi_hash_table1  
(
name STRING,                    
id BIGINT,
mobile BIGINT,
info STRING,
created_time STRING,
address STRING, 
PRIMARY KEY(name)  
) PARTITION BY HASH(name) PARTITIONS 4
STORED AS KUDU; 

多字段分区:

CREATE TABLE multi_hash_table2  
(
id BIGINT,
name STRING,                    
mobile BIGINT,
info STRING,
created_time STRING,
address STRING, 
PRIMARY KEY(id,name)  
) PARTITION BY HASH(id,name) PARTITIONS 4
STORED AS KUDU; 

混合分区:

CREATE TABLE multi_mix_table1  
( 
id BIGINT,
year INT,
name STRING,                    
mobile BIGINT,
info STRING,
created_time STRING,
address STRING, 
PRIMARY KEY(id,year)
)  
PARTITION BY HASH(id) PARTITIONS 4,  
RANGE(year) (  
	PARTITION 2000 <= VALUES < 2005,  
	PARTITION 2005 <= VALUES < 2010,  
	PARTITION 2010 <= VALUES < 2015,  
	PARTITION 2015 <= VALUES < 2020  
) STORED AS KUDU;  

show partitions multi_mix_table1;

posted on 2021-08-31 14:43  匍匐的仰望者  阅读(328)  评论(0编辑  收藏  举报

导航