Access OSS Tables by using EMR Serverless StarRocks

Updated at:

Access OSS Tables from Alibaba Cloud EMR Serverless StarRocks, a fully managed service. Use standard SQL to create tables, write data, and query data.

Prerequisites

  • An Alibaba Cloud AccessKey pair (AccessKey ID and AccessKey secret)

  • A Table Bucket in OSS Tables. If you have not created one, see OSS tables.

Important

StarRocks Community Edition has a known issue in which the specified S3FileIO does not take effect (see GitHub Issue #78141). Before you use it, contact an OSS O&M engineer to enable the ListObjectsV2 permission for the OSS Table Bucket.

Step 1: Prepare the environment

Purchase an EMR Serverless StarRocks instance

Log on to the EMR console and purchase an EMR Serverless StarRocks instance.

Configure access credentials

To access the data files in OSS Tables, configure the AccessKey pair (AccessKey ID and AccessKey secret) of your Alibaba Cloud account.

In the EMR Serverless StarRocks console, go to the product page of the target instance, click the Parameter Settings tab, and then perform the following steps:

  1. Disable the existing password-free access. Delete the values of the corresponding configuration items in the following files and leave the configuration items blank.

    In core-site.xml:

    fs.oss.credentials.provider =

    jindosdk.cfg:

    fs.oss.provider.format =
    fs.oss.provider.endpoint =
  2. Add the AccessKey pair of your Alibaba Cloud account. On the Parameter Settings tab, click Add Configuration Item and add the following configuration items:

    In core-site.xml:

    fs.oss.accessKeyId = <Alibaba Cloud AccessKey ID>
    fs.oss.accessKeySecret = <Alibaba Cloud AccessKey secret>

    jindosdk.cfg:

    fs.oss.accessKeyId = <Alibaba Cloud AccessKey ID>
    fs.oss.accessKeySecret = <Alibaba Cloud AccessKey secret>
  3. Apply the configurations. On the Parameter Settings tab, click Submit Parameters. After the configurations take effect, you can access the data files in OSS Tables.

Note

For complete information about custom AccessKey configuration in EMR Serverless StarRocks, see EMR Serverless StarRocks FAQ.

Step 2: Create an Iceberg REST catalog

The following example uses the Table Bucket name my-data-lake and the region cn-hangzhou. The corresponding Table Bucket ARN is acs:osstables:cn-hangzhou:{accountId}:bucket/my-data-lake.

Note

Unlike StarRocks Community Edition, EMR Serverless StarRocks requires no additional aws.s3.* parameters on the data plane. EMR automatically handles the access credentials and endpoint of the data plane.

Run the following statement to create an Iceberg REST catalog:

CREATE EXTERNAL CATALOG starrocks_osstables PROPERTIES(
  "type" = "iceberg",
  "iceberg.catalog.type" = "rest",

  -- Metadata plane
  "iceberg.catalog.uri" = "https://cn-hangzhou-internal.oss-tables.aliyuncs.com/iceberg",
  "iceberg.catalog.rest.sigv4-enabled" = "true",
  "iceberg.catalog.rest.signing-name" = "osstables",
  "iceberg.catalog.rest.signing-region" = "cn-hangzhou",
  "iceberg.catalog.rest.access-key-id" = "<Alibaba Cloud AccessKey ID>",
  "iceberg.catalog.rest.secret-access-key" = "<Alibaba Cloud AccessKey secret>",
  "iceberg.catalog.warehouse" = "acs:osstables:cn-hangzhou:{accountId}:bucket/my-data-lake",
  "iceberg.catalog.io-impl" = "org.apache.iceberg.aws.s3.S3FileIO"
);

Catalog parameters

The following table describes the parameters in the statement.

Parameter

Required

Description

iceberg.catalog.type

Yes

The implementation type of the Iceberg catalog. Set the value to rest.

iceberg.catalog.uri

Yes

The endpoint of the OSS Tables metadata service. Internal: https://{region}-internal.oss-tables.aliyuncs.com/iceberg. Internet: https://{region}.oss-tables.aliyuncs.com/iceberg.

iceberg.catalog.rest.sigv4-enabled

Yes

Set the value to true to enable sigv4 signature authentication.

iceberg.catalog.rest.signing-name

Yes

The name of the signing service. Set the value to osstables.

iceberg.catalog.rest.signing-region

Yes

The signing region. Set the value to the region where the Table Bucket resides, for example, cn-hangzhou.

iceberg.catalog.warehouse

Yes

The ARN of the Table Bucket. Format: acs:osstables:<Region>:<Alibaba Cloud account ID>:bucket/<Table Bucket name>.

iceberg.catalog.io-impl

Yes

The FileIO implementation. Set the value to org.apache.iceberg.aws.s3.S3FileIO.

Step 3: Use SQL to manage data

After the catalog is created, use standard SQL statements to manage data.

Create a database and table

Run the following SQL statements:

-- Switch the catalog
SET CATALOG starrocks_osstables;

-- Create a database
CREATE DATABASE starrocks_osstables_db;

-- Create a table
CREATE TABLE starrocks_osstables_db.users (
    id BIGINT NOT NULL COMMENT 'User ID',
    name STRING COMMENT 'Username',
    email STRING COMMENT 'Email',
    created_at DATETIME COMMENT 'Creation time'
);

Write and query data

Run the following SQL statements to write and query data:

-- Insert data
INSERT INTO starrocks_osstables_db.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 the entire table
SELECT * FROM starrocks_osstables_db.users;

-- Conditional query
SELECT * FROM starrocks_osstables_db.users WHERE id = 2;

-- Aggregate query
SELECT COUNT(*) AS total FROM starrocks_osstables_db.users;

The conditional query returns the row where id is 2, and the aggregate query returns the total number of rows in the table.

Usage notes

  • Data plane configuration — When you run CREATE CATALOG in EMR Serverless StarRocks, you do not need to configure the aws.s3.* data plane parameters. EMR handles them automatically. Configure only the metadata plane parameters.

  • Data maintenance — OSS Tables provides built-in file merge, snapshot cleanup, and unreferenced file cleanup. No manual maintenance operations are required. For more information, see Data maintenance.