做像58同城樣的網(wǎng)站百度網(wǎng)登錄入口
湖倉一體(Data Lakehouse)融合了數(shù)據(jù)倉庫的高性能、實時性以及數(shù)據(jù)湖的低成本、靈活性等優(yōu)勢,幫助用戶更加便捷地滿足各種數(shù)據(jù)處理分析的需求。在過去多個版本中,Apache Doris 持續(xù)加深與數(shù)據(jù)湖的融合,已演進(jìn)出一套成熟的湖倉一體解決方案。
為便于用戶快速入門,我們將通過系列文章介紹 Apache Doris 與各類主流數(shù)據(jù)湖格式及存儲系統(tǒng)的湖倉一體架構(gòu)搭建指南,包括 Hudi、Iceberg、Paimon、OSS、Delta Lake、Kudu、BigQuery 等。目前,我們已經(jīng)發(fā)布了 Apache Doris + Apache Hudi 快速搭建指南|Lakehouse 使用手冊(一),通過此文你可了解到在 Docker 環(huán)境下,如何快速搭建 Apache Doris + Apache Hudi 的測試及演示環(huán)境。
本文我們將再續(xù)前言,為大家介紹 Lakehouse 使用手冊(二)之 Apache Doris + Apache Paimon 搭建指南。
Apache Doris + Apache Paimon
Apache Paimon 是一種數(shù)據(jù)湖格式,并創(chuàng)新性地將數(shù)據(jù)湖格式和 LSM 結(jié)構(gòu)的優(yōu)勢相結(jié)合,成功將高效的實時流更新能力引入數(shù)據(jù)湖架構(gòu)中,這使得 Paimon 能夠?qū)崿F(xiàn)數(shù)據(jù)的高效管理和實時分析,為構(gòu)建實時湖倉架構(gòu)提供了強(qiáng)大的支撐。
為了充分發(fā)揮 Paimon 的能力,提高對 Paimon 數(shù)據(jù)的查詢效率,Apache Doris 對 Paimon 的多項最新特性提供了原生支持:
- 支持 Hive Metastore、FileSystem 等多種類型的 Paimon Catalog。
- 原生支持 Paimon 0.6 版本發(fā)布的 Primary Key Table Read Optimized 功能。
- 原生支持 Paimon 0.8 版本發(fā)布的 Primary Key Table Deletion Vector 功能。
基于 Apache Doris 的高性能查詢引擎和 Apache Paimon 高效的實時流更新能力,用戶可以實現(xiàn):
- 數(shù)據(jù)實時入湖: 借助 Paimon 的 LSM-Tree 模型,數(shù)據(jù)入湖的時效性可以降低到分鐘級;同時,Paimon 支持包括聚合、去重、部分列更新在內(nèi)的多種數(shù)據(jù)更新能力,使得數(shù)據(jù)流動更加靈活高效。
- 高性能數(shù)據(jù)處理分析: Paimon 所提供的 Append Only Table、Read Optimized、Deletion Vector 等技術(shù),可與 Doris 強(qiáng)大的查詢引擎對接,實現(xiàn)湖上數(shù)據(jù)的快速查詢及分析響應(yīng)。
未來 Apache Doris 將會逐步支持包括 Time Travel、增量數(shù)據(jù)讀取在內(nèi)的 Apache Paimon 更多高級特性,共同構(gòu)建統(tǒng)一、高性能、實時的湖倉平臺。
本文將會再 Docker 環(huán)境中,為讀者講解如何快速搭建 Apache Doris + Apache Paimon 測試 & 演示環(huán)境,并展示各功能的使用操作。
使用指南
本文涉及腳本&代碼從該地址獲取:https://github.com/apache/doris/tree/master/samples/datalake/iceberg_and_paimon
01 環(huán)境準(zhǔn)備
本文示例采用 Docker Compose 部署,組件及版本號如下:
Apache Doris 2.1.5 為全新發(fā)布:| 下載地址 | Release Notes
02 環(huán)境部署
1. 啟動所有組件
bash ./start_all.sh
2. 啟動后,可以使用如下腳本,登陸 Flink 命令行或 Doris 命令行:
bash ./start_flink_client.sh
bash ./start_doris_client.sh
03 數(shù)據(jù)準(zhǔn)備
首先登陸 Flink 命令行后,可以看到一張預(yù)構(gòu)建的表。表中已經(jīng)包含一些數(shù)據(jù),我們可以通過 Flink SQL 進(jìn)行查看。
Flink SQL> use paimon.db_paimon;
[INFO] Execute statement succeed.Flink SQL> show tables;
+------------+
| table name |
+------------+
| customer |
+------------+
1 row in setFlink 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 setFlink 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 setFlink 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 數(shù)據(jù)查詢
如下所示,Doris 集群中已經(jīng)創(chuàng)建了名為paimon
的 Catalog(可通過 SHOW CATALOGS
查看)。以下為該 Catalog 的創(chuàng)建語句:
-- 已創(chuàng)建,無需執(zhí)行
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 的數(shù)據(jù):
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 -ADatabase 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 讀取增量數(shù)據(jù)
我們可以通過 Flink SQL 更新 Paimon 表中的數(shù)據(jù):
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 執(zhí)行完畢后,在 Doris 中可直接查看到最新的數(shù)據(jù):
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 數(shù)據(jù)集上進(jìn)行了簡單的測試,分別使用了 Apache Doris 2.1.5 版本和 Trino 422 版本,均開啟 Primary Key Table Read Optimized 功能。
從測試結(jié)果可以看到,Doris 在標(biāo)準(zhǔn)靜態(tài)測試集上的平均查詢性能是 Trino 的 3 -5 倍,后續(xù)我們將針對 Deletion Vector 進(jìn)行優(yōu)化,進(jìn)一步提升真實業(yè)務(wù)場景下的查詢效率。
查詢優(yōu)化
對于基線數(shù)據(jù)來說,Apache Paimon 在 0.6 版本中引入 Primary Key Table Read Optimized 功能后,使得查詢引擎可以直接訪問底層的 Parquet/ORC 文件,大幅提升了基線數(shù)據(jù)的讀取效率。對于尚未合并的增量數(shù)據(jù)( INSERT、UPDATE 或 DELETE 所產(chǎn)生的數(shù)據(jù)增量)來說,可以通過 Merge-on-Read 的方式進(jìn)行讀取。此外,Paimon 在 0.8 版本中還引入的 Deletion Vector 功能,能夠進(jìn)一步提升查詢引擎對增量數(shù)據(jù)的讀取效率。
Apache Doris 支持通過原生的 Reader 讀取 Deletion Vector 并進(jìn)行 Merge on Read,我們通過 Doris 的 EXPLAIN
語句,來演示在一個查詢中,基線數(shù)據(jù)和增量數(shù)據(jù)的查詢方式。
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 進(jìn)行訪問(paimonNativeReadSplits=4/4
)。并且第一個分片的hasDeletionVector
的屬性為 true
,表示該分片有對應(yīng)的 Deletion Vector,讀取時會根據(jù) Deletion Vector 進(jìn)行數(shù)據(jù)過濾。
結(jié)束語
以上是基于 Apache Doris 與 Apache Paimon 快速搭建測試 / 演示環(huán)境的詳細(xì)指南,后續(xù)我們還將陸續(xù)推出 Apache Doris 與各類主流數(shù)據(jù)湖格式及存儲系統(tǒng)構(gòu)建湖倉一體架構(gòu)的系列指南,包括 Iceberg、OSS、Delta Lake 等,歡迎持續(xù)關(guān)注。