这里将StarRocks常用的命名加以记录。
建表语句
分区表
StarRocks支持动态分区。
create table tmp (
ds date comment '日期'
, city string comment '城市'
, distinct varchar(65533) NULL COMMENT "区域"
, num bigint comment '数量'
, money double comment '金额'
) ENGINE=OLAP
COMMENT "starRocks分区表创建语句demo"
PARTITION BY RANGE(ds)
(
START ("2021-01-01") END ("2022-10-31") EVERY (INTERVAL 1 DAY)
)
DISTRIBUTED BY HASH(city) BUCKETS 10
PROPERTIES (
"replication_num" = "3",
"colocate_with" = "tmp",
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.time_zone" = "Asia/Shanghai",
"dynamic_partition.end" = "7",
"dynamic_partition.prefix" = "p",
"dynamic_partition.buckets" = "1024",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);
非分区表
create table tmp (
ds date comment '日期'
, city string comment '城市'
, distinct varchar(65533) NULL COMMENT "区域"
, num bigint comment '数量'
, money double comment '金额'
) ENGINE = OLAP
DUPLICATE KEY(city)
COMMENT "starRocks非分区表建表语句demo"
DISTRIBUTED BY HASH(city) BUCKETS 8
PROPERTIES (
"replication_num" = "3",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);
DDL
SHOW CREATE TABLE detailDemo; -- 打印建表语句详情。可以查看分区
starRocks表在创建后新增分区
alter table tmp set ("dynamic_partition.enable" = "false");
alter table tmp add partitions START ("2022-11-10") END ("2022-11-30") EVERY (interval 1 day);
alter table tmp set ("dynamic_partition.enable" = "true");