Serverless StarRocks access to Fluss (Beta)
This topic describes how to query Fluss data through Serverless StarRocks.
Background information
Fluss can be registered as an external data source through the StarRocks External Catalog mechanism, enabling ad-hoc query and analysis of Fluss data. With StarRocks, you can:
-
Query streaming data in Fluss in real time, with second-level latency.
-
Query historical data that has been tiered to Paimon.
-
Use Union Read to merge real-time data in Fluss with historical data in Paimon in a single SQL statement, providing transparent access to hot and cold data.
Prerequisites
-
A Fluss cluster is created.
-
An EMR Serverless StarRocks instance is activated in the same VPC as the Fluss cluster. For details, see Create an instance.
Serverless StarRocks 3.3.13-1.2.0 or later.
Procedure
Step 1: Create a Fluss catalog
-
Log on to the EMR Serverless StarRocks console. On the instance list page, click Connect Instance in the Actions column of the target instance. For details, see Connect to a StarRocks instance through EMR StarRocks Manager.
-
In the SQL Editor, execute the following SQL statement to register Fluss as an external catalog:
CREATE EXTERNAL CATALOG <catalog_name> PROPERTIES ( 'type' = 'fluss', 'bootstrap.servers' = '<Fluss cluster bootstrap address>', 'fluss.option.client.security.protocol' = 'SASL', 'fluss.option.client.security.sasl.mechanism' = 'PLAIN', 'fluss.option.client.security.sasl.username' = '<Fluss username>', 'fluss.option.client.security.sasl.password' = '<Fluss password>' );
Parameter description
|
Parameter |
Required |
Description |
|
catalog_name |
Yes |
The catalog name. Only letters, digits, and underscores are allowed. Must start with a letter. Up to 64 characters. |
|
type |
Yes |
The data source type. Fixed as |
|
bootstrap.servers |
Yes |
The bootstrap address of the Fluss cluster. Available on the Fluss instance details page. |
|
fluss.option.client.security.protocol |
Yes |
The authentication protocol. Defaults to |
|
fluss.option.client.security.sasl.mechanism |
Yes |
The SASL authentication mechanism. Defaults to |
|
fluss.option.client.security.sasl.username |
Yes |
The username for SASL authentication. |
|
fluss.option.client.security.sasl.password |
Yes |
The password for SASL authentication. |
After the catalog is created, you can query it directly using the three-part name (Catalog.Database.Table) without switching context. The default Fluss database name is fluss:
SELECT * FROM <catalog_name>.<database_name>.<table_name>;
You can also switch to the Fluss catalog before querying:
-- Switch catalog and database
SET CATALOG <catalog_name>;
USE <db_name>;
-- Query the target table
SELECT COUNT(*) FROM <table_name> LIMIT 10;
Or, do it in one step:
USE <catalog_name>.<db_name>;
Step 2: Specify the query mode using a suffix
For Fluss tables that have enabled the lakehouse-stream integration (table.datalake.enabled = 'true' is set at table creation), data exists in both the Fluss cluster (real-time hot data) and the Paimon data lake (tiered historical data). StarRocks supports specifying the query mode by adding a suffix to the table name, enabling flexible access to data at different layers. The query modes are:
|
Query mode |
Suffix |
Description |
Applicable scenario |
|
Real-time data query |
|
Queries real-time incremental data in Fluss that has not yet been archived to the data lake, with second-level latency. |
Latency-sensitive scenarios such as real-time monitoring and alerting. |
|
Historical data query |
|
Queries the full historical data that has been tiered to Paimon. |
Offline analysis, reporting, and other similar scenarios. |
|
Merged query |
None |
StarRocks automatically merges the Fluss layer (hot data, second-level latency) with the Paimon layer (cold data, minute-level latency) and returns a complete, latest view. |
Scenarios requiring simultaneous access to hot and cold data. |
Consider an online sales order table order, which records user order data in real time (including fields such as order ID, order amount, order time, and region) and has enabled the lakehouse-stream integration. The following examples show typical business scenarios for the three query modes:
-- Scenario 1: Real-time monitoring of today's order count and amount ($rt, second-level latency)
SELECT COUNT(*) AS order_cnt, SUM(order_amount) AS total_amount
FROM `fluss_catalog`.`fluss`.order$rt
WHERE order_time >= CURRENT_DATE;
-- Scenario 2: Calculate week-over-week sales growth rate ($lake, query Paimon historical data)
SELECT
this_week AS this_week_sales,
last_week AS last_week_sales,
ROUND((this_week - last_week) * 100.0 / NULLIF(last_week, 0), 2) AS wow_growth_rate
FROM (
SELECT
SUM(CASE WHEN YEARWEEK(order_time) = YEARWEEK(CURRENT_DATE) THEN order_amount ELSE 0 END) AS this_week,
SUM(CASE WHEN YEARWEEK(order_time) = YEARWEEK(CURRENT_DATE) - 1 THEN order_amount ELSE 0 END) AS last_week
FROM `fluss_catalog`.`fluss`.order$lake
) t;
-- Scenario 3: Query total order amount by region in the past 7 days (no suffix, Union Read merges hot and cold data)
SELECT region, SUM(order_amount) AS total_amount
FROM `fluss_catalog`.`fluss`.order
WHERE order_time >= CURRENT_DATE - INTERVAL '7' DAY
GROUP BY region
ORDER BY total_amount DESC;
Related operations
View created catalogs
-- View all catalogs
SHOW CATALOGS;
-- View the CREATE statement of a specified catalog
SHOW CREATE CATALOG <catalog_name>;
View the Fluss table schema
DESCRIBE <catalog_name>.<database_name>.<table_name>;
View the Fluss database list
SHOW DATABASES FROM <catalog_name>;
Drop the Fluss catalog
Dropping a catalog only removes the mapping in StarRocks. The actual data in Fluss is not affected.
DROP CATALOG <catalog_name>;