kudu sql 实操

教程 犀牛 ⋅ 于 2021-06-03 22:45:14 ⋅ 1533 阅读

impala操作kudu

建表

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

file

  • hash分区且指定副本数
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

  • create as select
-- 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

  • range分区
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://hainiubl.com/topics/75594
成为第一个点赞的人吧 :bowtie:
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter