Access OSS Tables via Doris
This topic describes how to access OSS Tables via Apache Doris, using standard SQL to create tables, write data, and query data. Doris connects to OSS Tables through the Iceberg REST Catalog protocol.
Prerequisites
-
Doris 4.1.x or later has been deployed.
-
The MySQL client has been installed.
-
An Alibaba Cloud AccessKey (AccessKey ID and AccessKey Secret) has been obtained.
-
An OSS Tables Table Bucket has been created.
Step 1: Create a catalog
Connect to the Doris instance by using the MySQL client:
mysql -h 127.0.0.1 -P 9030 -u root
The following example uses the Table Bucket name my-data-lake and region cn-hangzhou. The corresponding Table Bucket ARN is acs:osstables:cn-hangzhou:{accountId}:bucket/my-data-lake.
CREATE CATALOG doris_osstables
PROPERTIES (
'type' = 'iceberg',
'iceberg.catalog.type' = 'rest',
'iceberg.rest.uri' = 'https://cn-hangzhou-internal.oss-tables.aliyuncs.com/iceberg',
'warehouse' = 'acs:osstables:cn-hangzhou:{accountId}:bucket/my-data-lake',
'iceberg.rest.signing-name' = 'osstables',
'iceberg.rest.signing-region' = 'cn-hangzhou',
'iceberg.rest.sigv4-enabled' = 'true',
'iceberg.rest.view-enabled' = 'false',
'io-impl' = 'org.apache.iceberg.aws.s3.S3FileIO',
'oss.endpoint' = 'https://oss-cn-hangzhou-internal.aliyuncs.com',
'oss.region' = 'cn-hangzhou',
'oss.access_key' = '<Alibaba Cloud AccessKey ID>',
'oss.secret_key' = '<Alibaba Cloud AccessKey Secret>',
'oss.use_path_style' = 'false',
'test_connection' = 'true'
);
Verify that the catalog is created:
SHOW CATALOGS;
A catalog named doris_osstables of type iceberg is displayed.
Configuration parameters
|
Parameter |
Required |
Description |
|
|
Yes |
The implementation type of the Iceberg Catalog. Fixed to |
|
|
Yes |
The OSS Tables Iceberg REST service address. Format:
|
|
|
Yes |
The Table Bucket ARN. Format: |
|
|
Yes |
Whether to enable SigV4 signature authentication. Fixed to |
|
|
Yes |
The service name used for SigV4 signing. Fixed to |
|
|
Yes |
The region used for SigV4 signing. It must be the same as the region of OSS Tables, such as |
|
|
Yes |
Whether to enable the Iceberg REST View feature. Set to |
|
|
Yes |
The FileIO implementation used by Iceberg to read and write data files. Fixed to |
|
|
Yes |
The OSS data access endpoint. Format:
|
|
|
Yes |
The region of the OSS Bucket. It must be the same as the region of the Table Bucket. |
|
|
Yes |
Whether to use Path Style to access objects. Fixed to |
|
|
No |
Whether to immediately test the connection when creating the catalog. When set to |
Step 2: Query data by using SQL
After the catalog is created, use standard SQL statements to operate on data.
Create a database and a table
-- Switch the catalog
SWITCH doris_osstables;
-- Create a database
CREATE DATABASE IF NOT EXISTS doris_osstables_db;
-- Show databases
SHOW DATABASES;
-- Use the database
USE doris_osstables_db;
-- Create a table
CREATE TABLE users (
id INT,
name STRING,
email STRING,
created_at DATETIME
)
PROPERTIES (
'write-format' = 'parquet',
'write.format.default' = 'parquet',
'format-version' = '2',
'write.parquet.compression-codec' = 'zstd'
);
-- Show the table structure
SHOW CREATE TABLE users;
Write and query data
-- Insert data
INSERT INTO users VALUES
(1, 'Alice', 'alice@example.com', '2024-01-15 10:30:00'),
(2, 'Bob', 'bob@example.com', '2024-01-16 14:20:00'),
(3, 'Carol', 'carol@example.com', '2024-01-17 09:15:00');
-- Query all rows
SELECT * FROM users ORDER BY id;
-- Conditional query
SELECT * FROM users WHERE id = 2;
-- Aggregate query
SELECT
COUNT(*) AS row_count,
COUNT(email) AS email_count
FROM users;
Verify data files
-- View the data file distribution
SELECT file_path, file_format, record_count
FROM `users$files`
ORDER BY file_path;
At least one data file is returned. The file_format is PARQUET, and the sum of record_count of all files is 3.
Notes
-
Version requirement: Doris 4.1.x or later is required.
-
Parameter differences: The REST Catalog configuration parameter names of Doris differ from those of StarRocks. Doris uses
iceberg.rest.uri(instead oficeberg.catalog.uri), and the data plane uses theoss.*prefix (instead ofaws.s3.*). -
Table properties: When you create a table, we recommend that you set
write-formattoparquetandformat-versionto2in PROPERTIES to support row-level updates and deletes. -
Data maintenance: OSS Tables provides built-in file compaction, snapshot cleanup, and orphan file cleanup. You do not need to perform maintenance operations manually. For more information, see Data maintenance.