数据库
首页 > 数据库> > kudu sql 实操

kudu sql 实操

作者:互联网

impala操作kudu

建表

CREATE TABLE xiniu.my_first_table
(
  id BIGINT,
  name STRING,
  PRIMARY KEY(id)
)
PARTITION BY HASH PARTITIONS 16
STORED AS KUDU;

file

CREATE TABLE xiniu.replicastable1
(
  id BIGINT,
  name STRING,
  PRIMARY KEY(id)
)
PARTITION BY HASH PARTITIONS 16
STORED AS KUDU
TBLPROPERTIES ('kudu.num_tablet_replicas' = '1')
;

默认副本数为3,查看副本数"kudu cluster ksck worker-2"

file

-- impala创建源表
create table xiniu.old_table (
    ts timestamp,
    name string,
    value string
);

-- create as old_table
create table xiniu.new_table
primary key (ts,name)
partition by hash (name) partitions 5
stored as kudu
as
select ts,name,value from old_table;

file

create table xiniu.range_table(
    id bigint,
    name string,
    primary key (id)
)
partition by range (id)
(
    partition value = 1,
    partition value = 100,
    partition value = 200,
    partition value = 300,
    partition value = 400,
    partition value = 500
)
stored as kudu
tblproperties ('kudu.num_tablet_replicas' = '1');

file

file

-- 组合主键必须放在表字段的最前面
-- 分组键必须为主键
create table xiniu.combin_partition_table(
    id bigint,
    age int,
    name string,
    primary key (id,age)
)
partition by hash (id) partitions 5,
range (age)
(
    partition VALUES < 10,
    partition 10 <= VALUES < 20,
    partition 20 <= VALUES < 30,
    partition 30 <= VALUES < 40,
    partition 40 <= VALUES < 60
)
stored as kudu
tblproperties ('kudu.num_tablet_replicas' = '3')
;

file

alter table xiniu.combin_partition_table add range partition 60 < values < 100;

file

alter table xiniu.combin_partition_table drop range partition value = 60;

file

插入数据

-- 单条插入
INSERT INTO my_first_table VALUES (99, "sarah");
-- 多条插入
INSERT INTO my_first_table VALUES (1, "john"), (2, "jane"), (3, "jim");
-- upsert 如果主键存在则修改,如果不存在则新增
UPSERT INTO my_first_table VALUES (99, "zoe");
UPSERT INTO my_first_table VALUES (88, "zoe");

file

file

修改数据

-- update语法仅限于在impala中操作kudu表
UPDATE xiniu.my_first_table SET name="bob" where id = 3;

file

file

删除数据

-- delete语法仅限于在impala中操作kudu表
DELETE FROM xiniu.my_first_table WHERE id < 3;

file

修改表名

ALTER TABLE xiniu.my_first_table RENAME TO xiniu.my_new_table;

file

impala关联kudu表

create EXTERNAL table xiniu.testbyapimapping 
stored as kudu
TBLPROPERTIES (
  'kudu.table_name' = 'xiniu.testbyapi'
);

file

海汼部落原创文章,原文链接:http://www.hainiubl.com/topics/75594

标签:name,partition,实操,sql,table,kudu,xiniu,id
来源: https://blog.csdn.net/heqingcool/article/details/117549941