兼容Trino Connector,扩展Apache Doris数据源接入能力|Lakehouse 使用手册(四)

技术分享
2024/09/06
SelectDB 技术团队

Apache Doris 内置支持包括 Hive、IcebergHudiPaimon、LakeSoul、JDBC 在内的多种 Catalog,并为其提供原生高性能且稳定的访问能力,以满足与数据湖的集成需求。而随着 Apache Doris 用户的增加,新的数据源连接需求也随之增加。因此,从 3.0 版本开始,Apache Doris 引入了 Trino Connector 兼容框架。

Trino/Presto 作为业界较早应用于湖仓查询、联邦分析的计算引擎,以广泛的数据源对接能力闻名。支持包括 Hive、Iceberg、Hudi、Paimon、Delta Lake、Kudu、BigQuery、Redis、Kafka 在内的数十种数据源,而这一能力主要得益于其插件化的 Connector 框架。Apache Doris 为快速提升数据接入能力与扩展性,并减少对每个数据源支持的开发工作量,选择兼容现有的 Connector 框架是一种高效且合理的解决方案。

通过兼容 Connector 插件,Apache Doris 能够支持 Trino/Presto 可对接的所有数据源,而无需改动 Doris 的内核代码。 该兼容框架不依赖 Trino 服务本身,仅需将编译好的 Connector 插件 JAR 文件部署到 Doris 集群即可使用。对于用户自研的 Connector 插件,也可以快速对接,实现业务平滑迁移。这一结合,为用户提供了更加完善、开放和高性能的查询服务。

目前 Apache Doris 已完成以下 Connector 适配:

Trino Connector 插件兼容方案作为 Apache Doris Catalog 功能的补充,旨在帮助用户快速进行数据源集成和基础的数据迁移,在性能和兼容性方面可能存在不足,欢迎加入社区一同改进。对于 Hive、Iceberg、Hudi、Paimon 等数据源,建议使用 Apache Doris 原生 Catalog 进行访问, 以便于获得最好的性能和稳定性。

本文将帮忙读者快速了解,如何在 Docker 环境下快速搭建 Apache Doris + Apache Delta Lake + Apache Kudu 测试 & 演示环境,并演示如何在 Doris 中适配一个新的 Trino Connector 插件。

使用指南

本文涉及脚本&代码从该地址获取:

https://github.com/apache/doris/tree/master/samples/datalake/deltalake_and_kudu

01 环境准备

本文示例采用 Docker Compose 部署,组件及版本号如下:

使用指南-环节准备.png

02 环境部署

1. 创建新的网络

 docker network create -d bridge trinoconnector-net

2. 启动所有组件

sh start-trinoconnector-compose.sh

3. 启动后,可以使用如下脚本,登陆 Doris 命令行

sh login-doris.sh

03 创建 Catalog

登陆 Doris 命令行后,Doris 集群中已创建了名为 delta_lakekudu_catalog 的 Catalog(可通过 SHOW CATALOGS/ SHOW CREATE CATALOG ${catalog_name}查看)。以下为这两个 Catalog 的创建语句:

-- 已创建,无需执行
create catalog delta_lake properties (
  "type"="trino-connector",
  "trino.connector.name"="delta_lake",
  "trino.hive.metastore.uri"="thrift://hive-metastore:9083",
  "trino.hive.s3.endpoint"="http://minio:9000",
  "trino.hive.s3.region"="us-east-1",
  "trino.hive.s3.aws-access-key"="minio",
  "trino.hive.s3.aws-secret-key"="minio123",
  "trino.hive.s3.path-style-access"="true"
);

CREATE CATALOG `kudu_catalog` PROPERTIES (
    "type" = "trino-connector",
    "trino.connector.name" = "kudu",
    "trino.kudu.authentication.type" = "NONE",
    "trino.kudu.client.master-addresses" = "kudu-master-1:7051,kudu-master-2:7151,kudu-master-3:7251"
);

04 数据查询

在启动的 Docker 环境中,可直接在 Doris 集群中查询 Deltalake 和 Kudu 的数据:

  • 查询 Deltalake 表数据

    mysql> switch delta_lake;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> use default;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> select * from customer limit 10;
    +-----------+--------------------+------------------------------------+-------------+-----------------+-----------+--------------+---------------------------------------------------------------------------------------------------------------+
    | c_custkey | c_name             | c_address                          | c_nationkey | c_phone         | c_acctbal | c_mktsegment | c_comment                                                                                                     |
    +-----------+--------------------+------------------------------------+-------------+-----------------+-----------+--------------+---------------------------------------------------------------------------------------------------------------+
    |         2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak     |          13 | 23-768-687-3665 |    121.65 | AUTOMOBILE   | l accounts. blithely ironic theodolites integrate boldly: caref                                               |
    |        34 | Customer#000000034 | Q6G9wZ6dnczmtOx509xgE,M2KV         |          15 | 25-344-968-5422 |   8589.70 | HOUSEHOLD    | nder against the even, pending accounts. even                                                                 |
    |        66 | Customer#000000066 | XbsEqXH1ETbJYYtA1A                 |          22 | 32-213-373-5094 |    242.77 | HOUSEHOLD    | le slyly accounts. carefully silent packages benea                                                            |
    |        98 | Customer#000000098 | 7yiheXNSpuEAwbswDW                 |          12 | 22-885-845-6889 |   -551.37 | BUILDING     | ages. furiously pending accounts are quickly carefully final foxes: busily pe                                 |
    |       130 | Customer#000000130 | RKPx2OfZy0Vn 8wGWZ7F2EAvmMORl1k8iH |           9 | 19-190-993-9281 |   5073.58 | HOUSEHOLD    | ix slowly. express packages along the furiously ironic requests integrate daringly deposits. fur              |
    |       162 | Customer#000000162 | JE398sXZt2QuKXfJd7poNpyQFLFtth     |           8 | 18-131-101-2267 |   6268.99 | MACHINERY    | accounts along the doggedly special asymptotes boost blithely during the quickly regular theodolites. slyly   |
    |       194 | Customer#000000194 | mksKhdWuQ1pjbc4yffHp8rRmLOMcJ      |          16 | 26-597-636-3003 |   6696.49 | HOUSEHOLD    | quickly across the fluffily dogged requests. regular platelets around the ironic, even requests cajole quickl |
    |       226 | Customer#000000226 | ToEmqB90fM TkLqyEgX8MJ8T8NkK       |           3 | 13-452-318-7709 |   9008.61 | AUTOMOBILE   | ic packages. ideas cajole furiously slyly special theodolites: carefully express pinto beans acco             |
    |       258 | Customer#000000258 | 7VbADek8qYezQYotxNUmnNI            |          12 | 22-278-425-9944 |   6022.27 | MACHINERY    | about the regular, bold accounts; pending packages use furiously stealthy warhorses. bold accounts sleep fur  |
    |       290 | Customer#000000290 | 8OlPT9G 8UqVXmVZNbmxVTPO8          |           4 | 14-458-625-5633 |   1811.35 | MACHINERY    | sts. blithely pending requests sleep fluffily on the regular excuses. carefully expre                         |
    +-----------+--------------------+------------------------------------+-------------+-----------------+-----------+--------------+---------------------------------------------------------------------------------------------------------------+
    10 rows in set (0.12 sec)
    
  • 查询 Kudu 表数据

    mysql> switch kudu_catalog;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> use default;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    
    mysql> select * from test_table limit 10;
    +------+----------+--------+
    | key  | value    | added  |
    +------+----------+--------+
    |    0 | NULL     | 12.345 |
    |    4 | NULL     | 12.345 |
    |   20 | NULL     | 12.345 |
    |   26 | NULL     | 12.345 |
    |   29 | value 29 | 12.345 |
    |   42 | NULL     | 12.345 |
    |   50 | NULL     | 12.345 |
    |   56 | NULL     | 12.345 |
    |   66 | NULL     | 12.345 |
    |   74 | NULL     | 12.345 |
    +------+----------+--------+
    10 rows in set (1.49 sec)
    
  • 联邦查询

    mysql> select * from delta_lake.`default`.customer c join kudu_catalog.`default`.test_table t on c.c_custkey = t.`key` where c.c_custkey < 50;
    +-----------+--------------------+---------------------------------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+------+----------+--------+
    | c_custkey | c_name             | c_address                             | c_nationkey | c_phone         | c_acctbal | c_mktsegment | c_comment                                                                                              | key  | value    | added  |
    +-----------+--------------------+---------------------------------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+------+----------+--------+
    |         1 | Customer#000000001 | IVhzIApeRb ot,c,E                     |          15 | 25-989-741-2988 |    711.56 | BUILDING     | to the even, regular platelets. regular, ironic epitaphs nag e                                         |    1 | value 1  | 12.345 |
    |        33 | Customer#000000033 | qFSlMuLucBmx9xnn5ib2csWUweg D         |          17 | 27-375-391-1280 |    -78.56 | AUTOMOBILE   | s. slyly regular accounts are furiously. carefully pending requests                                    |   33 | value 33 | 12.345 |
    |         3 | Customer#000000003 | MG9kdTD2WBHm                          |           1 | 11-719-748-3364 |   7498.12 | AUTOMOBILE   |  deposits eat slyly ironic, even instructions. express foxes detect slyly. blithely even accounts abov |    3 | value 3  | 12.345 |
    |        35 | Customer#000000035 | TEjWGE4nBzJL2                         |          17 | 27-566-888-7431 |   1228.24 | HOUSEHOLD    | requests. special, express requests nag slyly furiousl                                                 |   35 | value 35 | 12.345 |
    |         2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak        |          13 | 23-768-687-3665 |    121.65 | AUTOMOBILE   | l accounts. blithely ironic theodolites integrate boldly: caref                                        |    2 | NULL     | 12.345 |
    |        34 | Customer#000000034 | Q6G9wZ6dnczmtOx509xgE,M2KV            |          15 | 25-344-968-5422 |   8589.70 | HOUSEHOLD    | nder against the even, pending accounts. even                                                          |   34 | NULL     | 12.345 |
    |        32 | Customer#000000032 | jD2xZzi UmId,DCtNBLXKj9q0Tlp2iQ6ZcO3J |          15 | 25-430-914-2194 |   3471.53 | BUILDING     | cial ideas. final, furious requests across the e                                                       |   32 | NULL     | 12.345 |
    +-----------+--------------------+---------------------------------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+------+----------+--------+
    7 rows in set (0.13 sec)
    

适配新的 Trino Connector

本小节以 Trino Kafka Connector 插件为例,演示如何在 Doris 中适配 Trino Connector 插件,以及通过 Doris 的 Trino-Connector-Catalog 访问对应数据源。

节选自 Apache Doris 官网文档,完整内容可见:如何接入一个新的 Trino Connector 插件 - Apache Doris

01 编译 Kakfa Connector 插件

Trino 官方并未提供编译好的 Connector 插件,因此需要根据需求自行编译。编译步骤如下:

  • 拉取 Trino 源码: $ git clone https://github.com/trinodb/trino.git
  • 将 Trino 切换至 435 版本: $ git checkout 435
  • 进入 Kafka 插件源码目录: $ cd trino/plugin/trino-kafka
  • 编译 Kafka 插件: $ mvn clean install -DskipTest
  • 编译完成后,trino/plugin/trino-kafka/ 目录下会生成target/trino-kafka-435目录

注意:

  • 每一个 Connector 插件都是一个子目录,不是 JAR 包。

  • 由于 Doris 当前使用 435 版本的 trino-main 包,建议编译 435 版本的 Connector 插件。其他版本的 Connector 插件可能会存在兼容性问题。如在使用中遇到问题,随时向 Apache Doris 社区反馈。

02 设置 Doris 的 fe.conf / be.conf

Kafka Connector 插件编译完成后,需对 Doris 的 fe.conf be.conf 进行配置,使 Doris 能够找到该插件。

首先将上述准备好的 trino-kafka-435 目录存放在 /path/to/connectors 目录下,接着进行配置:

  • fe.conf: 在 fe.conf 文件中配置 trino_connector_plugin_dir=/path/to/connectors (若 fe.conf 中没有配置 trino_connector_plugin_dir 属性,则默认使用 ${Doris_HOME}/fe/connectors 目录)

  • be.conf: 在 be.conf 文件中配置 trino_connector_plugin_dir=/path/to/connectors (若 be.conf 中没有配置 trino_connector_plugin_dir 属性 ,则默认使用 ${Doris_HOME}/be/connectors 目录)

注意:Doris 采用懒加载的方式加载 Trino Connector 插件,这意味着如果第一次在 Doris 中使用 Trino-Connector Catalog 功能,无需重启 FE / BE 节点、Doris 会自动加载插件,且只加载 1 次。而如果 /path/to/connectors/ 目录下插件发生了变化,则需重启 FE / BE 节点,重新加载变化后的插件。

03 使用 Trino-Connector-Catalog 功能

完成前面步骤后,即可在 Doris 中使用 Trino-Connector Catalog 功能。

1. 在 Doris 中创建一个 Trino-Connector Catalog:

  create catalog kafka_tpch properties (
  "type"="trino-connector",
  -- 下面这四个属性来源于 trino,与 trino 的 etc/catalog/kakfa.properties 中的属性一致。
  "trino.connector.name"="kafka",
  "trino.kafka.table-names"="tpch.customer,tpch.orders,tpch.lineitem,tpch.part,tpch.partsupp,tpch.supplier,tpch.nation,tpch.region",
  "trino.kafka.nodes"="localhost:9092",
  "trino.kafka.table-description-dir" = "/mnt/datadisk1/fangtiewei"
  );
  • type关于 Catalog 类型必须设置为trino-connector` ;

  • 属性 trino.connector.nametrino.kafka.table-namestrino.kafka.nodestrino.kafka.table-description-dir 均来源于 Trino,具体可参考:Kafka connector

  • 不同的 Connector 插件应该设置不同的属性,可参考 Trino 官方文档:Connectors

2. 使用 Catalog

创建 Trino-Connector Catalog 后,使用方式与其他 Catalog 完全相同。通过 switch kafka_tpch 语句切换到该 Catalog 后,即可查询 Kafka 数据源中数据。

结束语

后续我们还将陆续推出 Apache Doris 与其他主流数据湖格式、存储系统构建湖仓一体架构的使用指南和方法论,请持续关注。

往期 Lakehouse 使用手册可查阅:

另外我们创建了数据湖/湖仓一体专项支持群,有需求的伙伴可扫描下方二维码申请加入(备注:湖仓一体),即可获得专职工程师的技术指导与支持。

湖仓一体专项支持群