As a new open data management architecture, the Data Lakehouse integrates the high performance and real-time capabilities of a data warehouse with the low cost and flexibility of a data lake, helping users more conveniently meet various data processing and analysis needs. It has been increasingly applied in enterprise big data systems.

In recent versions, Apache Doris has deepened its integration with data lakes and now offers a mature Data Lakehouse solution.

  • Since version 0.15, Apache Doris has introduced Hive and Iceberg external tables, exploring the capabilities of combining with Apache Iceberg for data lakes.
  • Starting from version 1.2, Apache Doris officially introduced the Multi-Catalog feature, enabling automatic metadata mapping and data access for various data sources, along with numerous performance optimizations for external data reading and query execution. It now fully supports building a high-speed and user-friendly Lakehouse architecture.
  • In version 2.1, Apache Doris further strengthened its Data Lakehouse architecture, enhancing the reading and writing capabilities of mainstream data lake formats (Hudi, Iceberg, Paimon, etc.), introducing compatibility with multiple SQL dialects, and seamless migration from existing systems to Apache Doris. For data science and large-scale data reading scenarios, Doris integrated the Arrow Flight high-speed reading interface, achieving a 100x improvement in data transfer efficiency.

Building Lakehouse using Doris and Iceberg

Apache Doris & Iceberg

Apache Iceberg is an open-source, high-performance, and highly reliable data lake table format that enables the analysis and management of massive-scale data. It supports various mainstream query engines, including Apache Doris, is compatible with HDFS and various object cloud storage, and features ACID compliance, schema evolution, advanced filtering, hidden partitioning, and partition layout evolution to ensure high-performance queries, data reliability, consistency, and flexibility with features like time travel and version rollback.

Apache Doris provides native support for several core features of Iceberg:

  • Supports multiple Iceberg Catalog types such as Hive Metastore, Hadoop, REST, Glue, Google Dataproc Metastore, DLF, etc.
  • Native support for Iceberg V1/V2 table formats and reading of Position Delete, Equality Delete files.
  • Supports querying Iceberg table snapshot history through table functions.
  • Supports Time Travel functionality.
  • Native support for the Iceberg table engine. It allows Apache Doris to directly create, manage, and write data to Iceberg tables. It supports comprehensive partition Transform functions, providing capabilities like hidden partitioning and partition layout evolution.

Users can quickly build an efficient Data Lakehouse solution based on Apache Doris + Apache Iceberg to flexibly address various real-time data analysis and processing needs.

  • Use the high-performance query engine of Doris to perform data analysis by associating Iceberg table data and other data sources, building a unified federated data analysis platform.
  • Manage and build Iceberg tables directly through Doris, complete data cleaning, processing, and writing to Iceberg tables in Doris, building a unified data processing platform for data lakes.
  • Share Doris data with other upstream and downstream systems for further processing through the Iceberg table engine, building a unified open data storage platform.

In the future, Apache Iceberg will serve as one of the native table engines for Apache Doris, providing more comprehensive analysis and management functions for lake-formatted data. Apache Doris will also gradually support more advanced features of Apache Iceberg, including Update/Delete/Merge, sorting during write-back, incremental data reading, metadata management, etc., to jointly build a unified, high-performance, real-time data lake platform.

For more information, please refer to Iceberg Catalog

User Guide

This document mainly explains how to quickly set up an Apache Doris + Apache Iceberg testing & demonstration environment in a Docker environment and demonstrate the usage of various functions.

All scripts and code mentioned in this document can be obtained from this address: https://github.com/apache/doris/tree/master/samples/datalake/iceberg_and_paimon

01 Environment Preparation

This document uses Docker Compose for deployment, with the following components and versions:

ComponentVersion
Apache DorisDefault 2.1.5, can be modified
Apache Iceberg1.4.3
MinIORELEASE.2024-04-29T09-56-05Z

02 Environment Deployment

  1. Start all components

    bash ./start_all.sh

  2. After starting, you can use the following script to log in to the Doris command line:

    1. -- login doris
    2. bash ./start_doris_client.sh

03 Create Iceberg Table

After logging into the Doris command line, an Iceberg Catalog named Iceberg has already been created in the Doris cluster (can be viewed by SHOW CATALOGS/SHOW CREATE CATALOG iceberg). The following is the creation statement for this Catalog:

  1. -- Already created
  2. CREATE CATALOG `iceberg` PROPERTIES (
  3. "type" = "iceberg",
  4. "iceberg.catalog.type" = "rest",
  5. "warehouse" = "s3://warehouse/",
  6. "uri" = "http://rest:8181",
  7. "s3.access_key" = "admin",
  8. "s3.secret_key" = "password",
  9. "s3.endpoint" = "http://minio:9000"
  10. );

Create a database and an Iceberg table in the Iceberg Catalog:

  1. mysql> SWITCH iceberg;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> CREATE DATABASE nyc;
  4. Query OK, 0 rows affected (0.12 sec)
  5. mysql> CREATE TABLE iceberg.nyc.taxis
  6. (
  7. vendor_id BIGINT,
  8. trip_id BIGINT,
  9. trip_distance FLOAT,
  10. fare_amount DOUBLE,
  11. store_and_fwd_flag STRING,
  12. ts DATETIME
  13. )
  14. PARTITION BY LIST (vendor_id, DAY(ts)) ()
  15. PROPERTIES (
  16. "compression-codec" = "zstd",
  17. "write-format" = "parquet"
  18. );
  19. Query OK, 0 rows affected (0.15 sec)

04 Data Insertion

Insert data into the Iceberg table:

  1. mysql> INSERT INTO iceberg.nyc.taxis
  2. VALUES
  3. (1, 1000371, 1.8, 15.32, 'N', '2024-01-01 9:15:23'),
  4. (2, 1000372, 2.5, 22.15, 'N', '2024-01-02 12:10:11'),
  5. (2, 1000373, 0.9, 9.01, 'N', '2024-01-01 3:25:15'),
  6. (1, 1000374, 8.4, 42.13, 'Y', '2024-01-03 7:12:33');
  7. Query OK, 4 rows affected (1.61 sec)
  8. {'status':'COMMITTED', 'txnId':'10085'}

Create an Iceberg table using CREATE TABLE AS SELECT:

  1. mysql> CREATE TABLE iceberg.nyc.taxis2 AS SELECT * FROM iceberg.nyc.taxis;
  2. Query OK, 6 rows affected (0.25 sec)
  3. {'status':'COMMITTED', 'txnId':'10088'}

05 Data Query

  • Simple query

    1. mysql> SELECT * FROM iceberg.nyc.taxis;
    2. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    3. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
    4. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    5. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
    6. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
    7. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
    8. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
    9. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    10. 4 rows in set (0.37 sec)
    11. mysql> SELECT * FROM iceberg.nyc.taxis2;
    12. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    13. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
    14. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    15. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
    16. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
    17. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
    18. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
    19. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    20. 4 rows in set (0.35 sec)
  • Partition pruning

    1. mysql> SELECT * FROM iceberg.nyc.taxis where vendor_id = 2 and ts >= '2024-01-01' and ts < '2024-01-02';
    2. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    3. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
    4. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    5. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
    6. +-----------+---------+---------------+-------------+--------------------+----------------------------+
    7. 1 row in set (0.06 sec)
    8. mysql> EXPLAIN VERBOSE SELECT * FROM iceberg.nyc.taxis where vendor_id = 2 and ts >= '2024-01-01' and ts < '2024-01-02';
    9. ....
    10. | 0:VICEBERG_SCAN_NODE(71)
    11. | table: taxis
    12. | predicates: (ts[#5] < '2024-01-02 00:00:00'), (vendor_id[#0] = 2), (ts[#5] >= '2024-01-01 00:00:00')
    13. | inputSplitNum=1, totalFileSize=3539, scanRanges=1
    14. | partition=1/0
    15. | backends:
    16. | 10002
    17. | s3://warehouse/wh/nyc/taxis/data/vendor_id=2/ts_day=2024-01-01/40e6ca404efa4a44-b888f23546d3a69c_5708e229-2f3d-4b68-a66b-44298a9d9815-0.zstd.parquet start: 0 length: 3539
    18. | cardinality=6, numNodes=1
    19. | pushdown agg=NONE
    20. | icebergPredicatePushdown=
    21. | ref(name="ts") < 1704153600000000
    22. | ref(name="vendor_id") == 2
    23. | ref(name="ts") >= 1704067200000000
    24. ....

    By examining the result of the EXPLAIN VERBOSE statement, it can be seen that the predicate condition vendor_id = 2 and ts >= '2024-01-01' and ts < '2024-01-02' ultimately only hits one partition (partition=1/0).

    It can also be observed that because a partition Transform function DAY(ts) was specified when creating the table, the original value in the data 2024-01-01 03:25:15.000000 will be transformed into the partition information in the file directory ts_day=2024-01-01.

06 Time Travel

Let’s insert a few more rows of data:

  1. INSERT INTO iceberg.nyc.taxis VALUES (1, 1000375, 8.8, 55.55, 'Y', '2024-01-01 8:10:22'), (3, 1000376, 7.4, 32.35, 'N', '2024-01-02 1:14:45');
  2. Query OK, 2 rows affected (0.17 sec)
  3. {'status':'COMMITTED', 'txnId':'10086'}
  4. mysql> SELECT * FROM iceberg.nyc.taxis;
  5. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  6. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
  7. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  8. | 3 | 1000376 | 7.4 | 32.35 | N | 2024-01-02 01:14:45.000000 |
  9. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
  10. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
  11. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
  12. | 1 | 1000375 | 8.8 | 55.55 | Y | 2024-01-01 08:10:22.000000 |
  13. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
  14. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  15. 6 rows in set (0.11 sec)

Use the iceberg_meta table function to query the snapshot information of the table:

  1. mysql> select * from iceberg_meta("table" = "iceberg.nyc.taxis", "query_type" = "snapshots");
  2. +---------------------+---------------------+---------------------+-----------+-----------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  3. | committed_at | snapshot_id | parent_id | operation | manifest_list | summary |
  4. +---------------------+---------------------+---------------------+-----------+-----------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  5. | 2024-07-29 03:38:22 | 8483933166442433486 | -1 | append | s3://warehouse/wh/nyc/taxis/metadata/snap-8483933166442433486-1-5f7b7736-8022-4ba1-9db2-51ae7553be4d.avro | {"added-data-files":"4","added-records":"4","added-files-size":"14156","changed-partition-count":"4","total-records":"4","total-files-size":"14156","total-data-files":"4","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0"} |
  6. | 2024-07-29 03:40:23 | 4726331391239920914 | 8483933166442433486 | append | s3://warehouse/wh/nyc/taxis/metadata/snap-4726331391239920914-1-6aa3d142-6c9c-4553-9c04-08ad4d49a4ea.avro | {"added-data-files":"2","added-records":"2","added-files-size":"7078","changed-partition-count":"2","total-records":"6","total-files-size":"21234","total-data-files":"6","total-delete-files":"0","total-position-deletes":"0","total-equality-deletes":"0"} |
  7. +---------------------+---------------------+---------------------+-----------+-----------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  8. 2 rows in set (0.07 sec)

Query a specified snapshot using the FOR VERSION AS OF statement:

  1. mysql> SELECT * FROM iceberg.nyc.taxis FOR VERSION AS OF 8483933166442433486;
  2. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  3. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
  4. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  5. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
  6. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
  7. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
  8. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
  9. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  10. 4 rows in set (0.05 sec)
  11. mysql> SELECT * FROM iceberg.nyc.taxis FOR VERSION AS OF 4726331391239920914;
  12. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  13. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
  14. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  15. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
  16. | 1 | 1000375 | 8.8 | 55.55 | Y | 2024-01-01 08:10:22.000000 |
  17. | 3 | 1000376 | 7.4 | 32.35 | N | 2024-01-02 01:14:45.000000 |
  18. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
  19. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
  20. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
  21. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  22. 6 rows in set (0.04 sec)

Query a specified snapshot using the FOR TIME AS OF statement:

  1. mysql> SELECT * FROM iceberg.nyc.taxis FOR TIME AS OF "2024-07-29 03:38:23";
  2. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  3. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
  4. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  5. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
  6. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
  7. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
  8. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
  9. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  10. 4 rows in set (0.04 sec)
  11. mysql> SELECT * FROM iceberg.nyc.taxis FOR TIME AS OF "2024-07-29 03:40:22";
  12. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  13. | vendor_id | trip_id | trip_distance | fare_amount | store_and_fwd_flag | ts |
  14. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  15. | 2 | 1000373 | 0.9 | 9.01 | N | 2024-01-01 03:25:15.000000 |
  16. | 1 | 1000374 | 8.4 | 42.13 | Y | 2024-01-03 07:12:33.000000 |
  17. | 2 | 1000372 | 2.5 | 22.15 | N | 2024-01-02 12:10:11.000000 |
  18. | 1 | 1000371 | 1.8 | 15.32 | N | 2024-01-01 09:15:23.000000 |
  19. +-----------+---------+---------------+-------------+--------------------+----------------------------+
  20. 4 rows in set (0.05 sec)