使用impala操作kudu
登录impala-shell,创建impala_kudu数据库。
1、创建表
CREATE TABLE student ( id int not null, name STRING null , adress STRING NULL ENCODING AUTO_ENCODING COMPRESSION DEFAULT_COMPRESSION, PRIMARY KEY (id) --主键 )PARTITION BY HASH (id) PARTITIONS 20--分区方式 STORED AS KUDU TBLPROPERTIES('kudu.master_addresses'='cdh01');
也可以CREATE TABLE ... AS SELECT
CREATE TABLE impala_kudu_student PRIMARY KEY (id) PARTITION BY HASH(id) PARTITIONS 8 STORED AS KUDU AS SELECT id,name,adress FROM student;
其中
主键创建原则:
字段数据类型包括:
ENCODING格式:
COMPRESSION类型:
分区方式:
TBLPROPERTIES:
可以设置kudu的表名和kudu.master_addresses及表类型等。
ALTER TABLE impala_kudu_student SET TBLPROPERTIES('EXTERNAL' = 'FALSE'); ALTER TABLE 表名 RENAME TO 新表名; ALTER TABLE 表名 SET TBLPROPERTIES('kudu.table_name' = '外部映射表') ALTER TABLE 表名 SET TBLPROPERTIES('kudu.master_addresses' = 'kudu master新地址');
2、插入数据
INSERT INTO impala_kudu.student (id, name, adress) VALUES(1, '张三', '00号');
3、更新数据
UPDATE student SET name="张三1" where id = 1;
4、删除数据
DELETE FROM student WHERE id =1;
5、删除表
drop table impala_kudu_student;