1. 基本概念
-
FE,Frontend,前端节点,接收用户查询请求,SQL解析,执行计划生成,元数据管理,节点管理等
-
BE,Backend,后端节点,数据存储,执行查询计划。
前端节点FE 和 后端节点BE 各自独立运行,互不影响。
-
broker:用来和外部文件系统打交道
2. 修改配置
DORIS_HOME=/export/server/doris-1.2.4.1
node1:安装doris的机器名
配置文件 | 修改参数 |
$DORIS_HOME/fe/conf/fe.conf | priority_networks = node1/24 meta_dir = DORIS_HOME/fe/doris-meta |
$DORIS_HOME/be/conf/be.conf | priority_networks = node1/24 storage_root_path = DORIS_HOME/be/storage1,10;DORIS_HOME/be/storage2 |
$DORIS_HOME//extensions/apache_hdfs_broker /conf/apache_hdfs_broker.conf |
3. 启动脚本
启动脚本 | 运行进程 |
$DORIS_HOME/fe/bin/start_fe.sh --daemon | PaloFe |
ulimit -n 60000 sysctl -w vm.max_map_count=2000000 $DORIS_HOME/be/bin/start_be.sh --daemon |
ps -ef | grep be |
$DORIS_HOME//extensions/apache_hdfs_broker/bin/start_broker.sh --daemon | BrokerBootstrap |
4. 停止脚本
$DORIS_HOME/fe/bin/stop_fe.sh |
$DORIS_HOME/be/bin/stop_be.sh |
$DORIS_HOME//extensions/apache_hdfs_broker/bin/stop_broker.sh |
5. Doris端口
常用端口
webui: node1:8030
FE上的MySQL Server端口: 9030
6. MySQL客户端连接Doris
mysql -uroot -P9030 -hnode1
-u 此处使用的root用户是doris内置的默认用户,也是超级管理员用户
-P:这是我们连接到Doris的查询端口,默认端口是9030,对应于fe.conf中的query_port
-h:这是我们连接的FE的IP地址,如果你的客户端和FE安装在同一个节点上,可以使用127.0.0.1
查看FE、BE、Broker运行状态
show frontends\G;
show backends\G;
show broker\G;
扩缩容
#1.扩容
#1.1添加前端
ALTER SYSTEM ADD FRONTEND "192.168.0.1:9050";
#1.2添加后端
ALTER SYSTEM ADD BACKEND "192.168.0.1:9050";
#2.缩容
#1.1剔除前端
ALTER SYSTEM DROP FRONTEND "host1:port", "host2:port";
#1.2剔除后端
ALTER SYSTEM DROP BACKEND "host1:port", "host2:port";
清屏: CTRL + L
7. 创建表
建表
修改分区
mysql> ALTER TABLE demo.example_tb1 ADD PARTITION IF NOT EXISTS `p202005` VALUES LESS THAN ("2020-06-01");
Query OK, 0 rows affected (0.54 sec)
mysql> ALTER TABLE demo.example_list_tb2 ADD PARTITION IF NOT EXISTS p_uk VALUES IN ("London");
Query OK, 0 rows affected (0.25 sec)
mysql> ALTER TABLE demo.example_tb1 DROP PARTITION IF EXISTS p202005;
Query OK, 0 rows affected (0.09 sec)
mysql> ALTER TABLE demo.example_list_tb2 DROP PARTITION IF EXISTS p_uk;
Query OK, 0 rows affected (0.03 sec)
分区可以省略,如果省略的话,默认Doris系统会创建一个分区,这个分区成为单分区,它的分区名字和表名一样。这种很常用。
数据模型
Aggregate Key,相同的key,value会做聚合操作。按照给定的聚合函数 (sum、max、min、replace) 进行聚合。
Unique Key,保证key列的唯一性。只要key相同,新的值会覆盖旧的值。
Duplicate Key,运行数据冗余存储,保留数据原始的样子,不会对数据做任何操作。
建表时,可以省略,默认是冗余模型。
8. 数据操作
数据导入
数据导出
数据删除
数据修改
9. Rollup 和 物化视图
Doris建表默认是有顺序的,这个顺序就是字段的顺序,可以认为这就是它默认的聚合索引。若根据某字段过滤数据,根据索引最左匹配原则,有可能索引失效,导致全表扫描。
rollup可以调整字段顺序,使字段顺序尽可能匹配过滤字段,以此增加前缀索引的匹配度,提升查询效率。
查看表的Rollup:
desc table_name all;
创建Rollup:
alter table table_name add rollup rollup_name (field1,field2...);
#1.创建rollup
mysql> alter table example_site_visit add rollup rollup_cost_userid(user_id,cost);
#2.再创建rollup
mysql>alter table example_site_visit add rollup rollup_cost_userid2(age,date,city,user_id,sex,last_visit_date,cost,max_dwell_time,min_dwell_time);
mysql> desc example_site_visit all;
+---------------------+---------------+-----------------+-------------+--------------+------+-------+---------------------+---------+---------+
| IndexName | IndexKeysType | Field | Type | InternalType | Null | Key | Default | Extra | Visible |
+---------------------+---------------+-----------------+-------------+--------------+------+-------+---------------------+---------+---------+
| example_site_visit | AGG_KEYS | user_id | LARGEINT | LARGEINT | No | true | NULL | | true |
| | | date | DATE | DATE | No | true | NULL | | true |
| | | city | VARCHAR(20) | VARCHAR(20) | Yes | true | NULL | | true |
| | | age | SMALLINT | SMALLINT | Yes | true | NULL | | true |
| | | sex | TINYINT | TINYINT | Yes | true | NULL | | true |
| | | last_visit_date | DATETIME | DATETIME | Yes | false | 1970-01-01 00:00:00 | REPLACE | true |
| | | cost | BIGINT | BIGINT | Yes | false | 0 | SUM | true |
| | | max_dwell_time | INT | INT | Yes | false | 0 | MAX | true |
| | | min_dwell_time | INT | INT | Yes | false | 99999 | MIN | true |
| | | | | | | | | | |
| rollup_cost_userid | AGG_KEYS | user_id | LARGEINT | LARGEINT | No | true | NULL | | true |
| | | cost | BIGINT | BIGINT | Yes | false | 0 | SUM | true |
| | | | | | | | | | |
| rollup_cost_userid2 | AGG_KEYS | age | SMALLINT | SMALLINT | Yes | true | NULL | | true |
| | | date | DATE | DATE | No | true | NULL | | true |
| | | city | VARCHAR(20) | VARCHAR(20) | Yes | true | NULL | | true |
| | | user_id | LARGEINT | LARGEINT | No | true | NULL | | true |
| | | sex | TINYINT | TINYINT | Yes | true | NULL | | true |
| | | last_visit_date | DATETIME | DATETIME | Yes | false | 1970-01-01 00:00:00 | REPLACE | true |
| | | cost | BIGINT | BIGINT | Yes | false | 0 | SUM | true |
| | | max_dwell_time | INT | INT | Yes | false | 0 | MAX | true |
| | | min_dwell_time | INT | INT | Yes | false | 99999 | MIN | true |
+---------------------+---------------+-----------------+-------------+--------------+------+-------+---------------------+---------+---------+
22 rows in set (0.01 sec)
物化视图
Doris的物化视图,本质上也是一个rollup,只是语法不一样。
mysql> CREATE MATERIALIZED VIEW example_site_visit_mv AS
-> SELECT user_id,city,SUM(cost)
-> FROM example_site_visit
-> GROUP BY user_id,city;
Query OK, 0 rows affected (0.20 sec)
mysql> desc example_site_visit all
10. 内置函数
语法:show builtin functions in database_name;
使用:show builtin functions in demo;
使用方式: help + 函数名;
请点击查看更多函数,查看左侧导航树
11. 动态分区
开启动态分区
#1.开启动态分区,root用户未设置密码,所以为空
curl --location-trusted -u root: -XGET http://node1:8030/api/_set_config?dynamic_partition_enable=true
#2.设置动态分区的检测时间间隔,root用户未设置密码,所以为空
curl --location-trusted -u root: -XGET http://node1:8030/api/_set_config?dynamic_partition_check_interval_seconds=5
动态分区语法
PARTITION BY RANGE('分区字段')()
动态分区不支持list分区
创建动态分区表
-- 创建分区
CREATE TABLE order_dynamic_partition
(
id int,
time date,
money double,
areaName varchar(50)
)
duplicate key(id,time)
PARTITION BY RANGE(time)()
DISTRIBUTED BY HASH(id) buckets 10
PROPERTIES(
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "DAY", --四种动态分区类型:HOUR,DAY,WEEK,MONTH
"dynamic_partition.start" = "-7", -- 保留到7天前的分区
"dynamic_partition.end" = "3", --也创建后3天的分区
"dynamic_partition.prefix" = "p", --分区名称前缀
"dynamic_partition.buckets" = "10",
"replication_num" = "1"
);
-- 查看分区
show partitions from order_dynamic_partition;
查看动态分区表
show dynamic partition tables;
动态分区表 与 静态分区表 的转换开关
"dynamic_partition.enable" = "true"文章来源:https://www.toymoban.com/news/detail-730856.html
true为开启动态分区,false为普通分区文章来源地址https://www.toymoban.com/news/detail-730856.html
-- 创建静态分区表
CREATE TABLE table_partition
(
id int,
time date,
money double,
areaName varchar(50)
)
duplicate key(id,time)
PARTITION BY RANGE(time)
(
PARTITION `p202001` VALUES LESS THAN ("2020-02-01"),
PARTITION `p202002` VALUES LESS THAN ("2020-03-01"),
PARTITION `p202003` VALUES LESS THAN ("2020-04-01")
)
DISTRIBUTED BY HASH(id) buckets 10
PROPERTIES
(
"dynamic_partition.enable" = "false",
"dynamic_partition.time_unit" = "DAY",
"dynamic_partition.prefix" = "p",
"dynamic_partition.end" = "3",
"dynamic_partition.buckets" = "10",
"replication_num" = "1"
);
-- 静态分区表转换为动态分区表
ALTER TABLE table_partition set ("dynamic_partition.enable" = "true");
-- 动态分区表转换为静态分区表
ALTER TABLE table_partition set ("dynamic_partition.enable" = "false");
到了这里,关于Apache Doris 快速入门的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!