湖倉一體(Data Lakehouse)融合了數據倉庫的高性能、實時性以及數據湖的低成本、靈活性等優勢,幫助用户更加便捷地滿足各種數據處理分析的需求。在過去多個版本中,Apache Doris 持續加深與數據湖的融合,已演進出一套成熟的湖倉一體解決方案。
為便於用户快速入門,我們將通過系列文章介紹 Apache Doris 與各類主流數據湖格式及存儲系統的湖倉一體架構搭建指南,包括 Hudi、Iceberg、Paimon、OSS、Delta Lake、Kudu、BigQuery 等。目前,我們已經發布了 Apache Doris + Apache Hudi 快速搭建指南|Lakehouse 使用手冊(一),通過此文你可瞭解到在 Docker 環境下,如何快速搭建 Apache Doris + Apache Hudi 的測試及演示環境。
本文我們將再續前言,為大家介紹 Lakehouse 使用手冊(二)之 Apache Doris + Apache Paimon 搭建指南。
Apache Doris + Apache Paimon
Apache Paimon 是一種數據湖格式,並創新性地將數據湖格式和 LSM 結構的優勢相結合,成功將高效的實時流更新能力引入數據湖架構中,這使得 Paimon 能夠實現數據的高效管理和實時分析,為構建實時湖倉架構提供了強大的支撐。
為了充分發揮 Paimon 的能力,提高對 Paimon 數據的查詢效率,Apache Doris 對 Paimon 的多項最新特性提供了原生支持:
- 支持 Hive Metastore、FileSystem 等多種類型的 Paimon Catalog。
- 原生支持 Paimon 0.6 版本發佈的 Primary Key Table Read Optimized 功能。
- 原生支持 Paimon 0.8 版本發佈的 Primary Key Table Deletion Vector 功能。
基於 Apache Doris 的高性能查詢引擎和 Apache Paimon 高效的實時流更新能力,用户可以實現:
- 數據實時入湖: 藉助 Paimon 的 LSM-Tree 模型,數據入湖的時效性可以降低到分鐘級;同時,Paimon 支持包括聚合、去重、部分列更新在內的多種數據更新能力,使得數據流動更加靈活高效。
- 高性能數據處理分析: Paimon 所提供的 Append Only Table、Read Optimized、Deletion Vector 等技術,可與 Doris 強大的查詢引擎對接,實現湖上數據的快速查詢及分析響應。
未來 Apache Doris 將會逐步支持包括 Time Travel、增量數據讀取在內的 Apache Paimon 更多高級特性,共同構建統一、高性能、實時的湖倉平台。
本文將會再 Docker 環境中,為讀者講解如何快速搭建 Apache Doris + Apache Paimon 測試 & 演示環境,並展示各功能的使用操作。
使用指南
本文涉及腳本&代碼從該地址獲取:https://github.com/apache/doris/tree/master/samples/datalake/iceberg\_and\_paimon
01 環境準備
本文示例採用 Docker Compose 部署,組件及版本號如下:
Apache Doris 2.1.5 為全新發布:| 下載地址 | Release Notes
02 環境部署
1. 啓動所有組件
bash ./start_all.sh
2. 啓動後,可以使用如下腳本,登陸 Flink 命令行或 Doris 命令行:
bash ./start_flink_client.sh
bash ./start_doris_client.sh
03 數據準備
首先登陸 Flink 命令行後,可以看到一張預構建的表。表中已經包含一些數據,我們可以通過 Flink SQL 進行查看。
Flink SQL> use paimon.db_paimon;
[INFO] Execute statement succeed.
Flink SQL> show tables;
+------------+
| table name |
+------------+
| customer |
+------------+
1 row in set
Flink SQL> show create table customer;
+------------------------------------------------------------------------+
| result |
+------------------------------------------------------------------------+
| CREATE TABLE `paimon`.`db_paimon`.`customer` (
`c_custkey` INT NOT NULL,
`c_name` VARCHAR(25),
`c_address` VARCHAR(40),
`c_nationkey` INT NOT NULL,
`c_phone` CHAR(15),
`c_acctbal` DECIMAL(12, 2),
`c_mktsegment` CHAR(10),
`c_comment` VARCHAR(117),
CONSTRAINT `PK_c_custkey_c_nationkey` PRIMARY KEY (`c_custkey`, `c_nationkey`) NOT ENFORCED
) PARTITIONED BY (`c_nationkey`)
WITH (
'bucket' = '1',
'path' = 's3://warehouse/wh/db_paimon.db/customer',
'deletion-vectors.enabled' = 'true'
)
|
+-------------------------------------------------------------------------+
1 row in set
Flink SQL> desc customer;
+--------------+----------------+-------+-----------------------------+--------+-----------+
| name | type | null | key | extras | watermark |
+--------------+----------------+-------+-----------------------------+--------+-----------+
| c_custkey | INT | FALSE | PRI(c_custkey, c_nationkey) | | |
| c_name | VARCHAR(25) | TRUE | | | |
| c_address | VARCHAR(40) | TRUE | | | |
| c_nationkey | INT | FALSE | PRI(c_custkey, c_nationkey) | | |
| c_phone | CHAR(15) | TRUE | | | |
| c_acctbal | DECIMAL(12, 2) | TRUE | | | |
| c_mktsegment | CHAR(10) | TRUE | | | |
| c_comment | VARCHAR(117) | TRUE | | | |
+--------------+----------------+-------+-----------------------------+--------+-----------+
8 rows in set
Flink SQL> select * from customer order by c_custkey limit 4;
+-----------+--------------------+--------------------------------+-------------+-----------------+-----------+--------------+--------------------------------+
| c_custkey | c_name | c_address | c_nationkey | c_phone | c_acctbal | c_mktsegment | c_comment |
+-----------+--------------------+--------------------------------+-------------+-----------------+-----------+--------------+--------------------------------+
| 1 | Customer#000000001 | IVhzIApeRb ot,c,E | 15 | 25-989-741-2988 | 711.56 | BUILDING | to the even, regular platel... |
| 2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak | 13 | 23-768-687-3665 | 121.65 | AUTOMOBILE | l accounts. blithely ironic... |
| 3 | Customer#000000003 | MG9kdTD2WBHm | 1 | 11-719-748-3364 | 7498.12 | AUTOMOBILE | deposits eat slyly ironic,... |
| 32 | Customer#000000032 | jD2xZzi UmId,DCtNBLXKj9q0Tl... | 15 | 25-430-914-2194 | 3471.53 | BUILDING | cial ideas. final, furious ... |
+-----------+--------------------+--------------------------------+-------------+-----------------+-----------+--------------+--------------------------------+
4 rows in set
04 數據查詢
如下所示,Doris 集羣中已經創建了名為paimon 的 Catalog(可通過 SHOW CATALOGS 查看)。以下為該 Catalog 的創建語句:
-- 已創建,無需執行
CREATE CATALOG `paimon` PROPERTIES (
"type" = "paimon",
"warehouse" = "s3://warehouse/wh/",
"s3.endpoint"="http://minio:9000",
"s3.access_key"="admin",
"s3.secret_key"="password",
"s3.region"="us-east-1"
);
你可登錄到 Doris 中查詢 Paimon 的數據:
mysql> use paimon.db_paimon;
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> show tables;
+---------------------+
| Tables_in_db_paimon |
+---------------------+
| customer |
+---------------------+
1 row in set (0.00 sec)
mysql> select * from customer order by c_custkey limit 4;
+-----------+--------------------+---------------------------------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+
| c_custkey | c_name | c_address | c_nationkey | c_phone | c_acctbal | c_mktsegment | c_comment |
+-----------+--------------------+---------------------------------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+
| 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 |
| 2 | Customer#000000002 | XSTf4,NCwDVaWNe6tEgvwfmRchLXak | 13 | 23-768-687-3665 | 121.65 | AUTOMOBILE | l accounts. blithely ironic theodolites integrate boldly: caref |
| 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 |
| 32 | Customer#000000032 | jD2xZzi UmId,DCtNBLXKj9q0Tlp2iQ6ZcO3J | 15 | 25-430-914-2194 | 3471.53 | BUILDING | cial ideas. final, furious requests across the e |
+-----------+--------------------+---------------------------------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+
4 rows in set (1.89 sec)
05 讀取增量數據
我們可以通過 Flink SQL 更新 Paimon 表中的數據:
Flink SQL> update customer set c_address='c_address_update' where c_nationkey = 1;
[INFO] Submitting SQL update statement to the cluster...
[INFO] SQL update statement has been successfully submitted to the cluster:
Job ID: ff838b7b778a94396b332b0d93c8f7ac
等 Flink SQL 執行完畢後,在 Doris 中可直接查看到最新的數據:
mysql> select * from customer where c_nationkey=1 limit 2;
+-----------+--------------------+-----------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+
| c_custkey | c_name | c_address | c_nationkey | c_phone | c_acctbal | c_mktsegment | c_comment |
+-----------+--------------------+-----------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+
| 3 | Customer#000000003 | c_address_update | 1 | 11-719-748-3364 | 7498.12 | AUTOMOBILE | deposits eat slyly ironic, even instructions. express foxes detect slyly. blithely even accounts abov |
| 513 | Customer#000000513 | c_address_update | 1 | 11-861-303-6887 | 955.37 | HOUSEHOLD | press along the quickly regular instructions. regular requests against the carefully ironic s |
+-----------+--------------------+-----------------+-------------+-----------------+-----------+--------------+--------------------------------------------------------------------------------------------------------+
2 rows in set (0.19 sec)
Benchmark
我們在 Paimon(0.8)版本的 TPCDS 1000 數據集上進行了簡單的測試,分別使用了 Apache Doris 2.1.5 版本和 Trino 422 版本,均開啓 Primary Key Table Read Optimized 功能。
從測試結果可以看到,Doris 在標準靜態測試集上的平均查詢性能是 Trino 的 3 -5 倍,後續我們將針對 Deletion Vector 進行優化,進一步提升真實業務場景下的查詢效率。
查詢優化
對於基線數據來説,Apache Paimon 在 0.6 版本中引入 Primary Key Table Read Optimized 功能後,使得查詢引擎可以直接訪問底層的 Parquet/ORC 文件,大幅提升了基線數據的讀取效率。對於尚未合併的增量數據( INSERT、UPDATE 或 DELETE 所產生的數據增量)來説,可以通過 Merge-on-Read 的方式進行讀取。此外,Paimon 在 0.8 版本中還引入的 Deletion Vector 功能,能夠進一步提升查詢引擎對增量數據的讀取效率。
Apache Doris 支持通過原生的 Reader 讀取 Deletion Vector 並進行 Merge on Read,我們通過 Doris 的 EXPLAIN 語句,來演示在一個查詢中,基線數據和增量數據的查詢方式。
mysql> explain verbose select * from customer where c_nationkey < 3;
+------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String(Nereids Planner) |
+------------------------------------------------------------------------------------------------------------------------------------------------+
| ............... |
| |
| 0:VPAIMON_SCAN_NODE(68) |
| table: customer |
| predicates: (c_nationkey[#3] < 3) |
| inputSplitNum=4, totalFileSize=238324, scanRanges=4 |
| partition=3/0 |
| backends: |
| 10002 |
| s3://warehouse/wh/db_paimon.db/customer/c_nationkey=1/bucket-0/data-15cee5b7-1bd7-42ca-9314-56d92c62c03b-0.orc start: 0 length: 66600 |
| s3://warehouse/wh/db_paimon.db/customer/c_nationkey=1/bucket-0/data-5d50255a-2215-4010-b976-d5dc656f3444-0.orc start: 0 length: 44501 |
| s3://warehouse/wh/db_paimon.db/customer/c_nationkey=2/bucket-0/data-e98fb7ef-ec2b-4ad5-a496-713cb9481d56-0.orc start: 0 length: 64059 |
| s3://warehouse/wh/db_paimon.db/customer/c_nationkey=0/bucket-0/data-431be05d-50fa-401f-9680-d646757d0f95-0.orc start: 0 length: 63164 |
| cardinality=18751, numNodes=1 |
| pushdown agg=NONE |
| paimonNativeReadSplits=4/4 |
| PaimonSplitStats: |
| SplitStat [type=NATIVE, rowCount=1542, rawFileConvertable=true, hasDeletionVector=true] |
| SplitStat [type=NATIVE, rowCount=750, rawFileConvertable=true, hasDeletionVector=false] |
| SplitStat [type=NATIVE, rowCount=750, rawFileConvertable=true, hasDeletionVector=false] |
| tuple ids: 0
| ............... | |
+------------------------------------------------------------------------------------------------------------------------------------------------+
67 rows in set (0.23 sec)
可以看到,對於剛才通過 Flink SQL 更新的表,包含 4 個分片,並且全部分片都可以通過 Native Reader 進行訪問(paimonNativeReadSplits=4/4)。並且第一個分片的hasDeletionVector的屬性為 true,表示該分片有對應的 Deletion Vector,讀取時會根據 Deletion Vector 進行數據過濾。
結束語
以上是基於 Apache Doris 與 Apache Paimon 快速搭建測試 / 演示環境的詳細指南,後續我們還將陸續推出 Apache Doris 與各類主流數據湖格式及存儲系統構建湖倉一體架構的系列指南,包括 Iceberg、OSS、Delta Lake 等,歡迎持續關注。