Skip to content

StarRocks ​

Bruin supports StarRocks as a native SQL data platform through its MySQL-compatible FE query port. This lets you build and materialize StarRocks tables, run data quality checks, and use sensors — in addition to using StarRocks as an ingestion source or destination.

StarRocks needs specific DDL to create tables (a table model, a DISTRIBUTED BY clause, PROPERTIES, and optionally PARTITION BY), which the generic MySQL adapter does not emit — the starrocks.* asset types below generate it.

Connection ​

Add a StarRocks entry under connections in .bruin.yml. The same connection is used for both native assets and ingestion.

yaml
connections:
  starrocks:
    - name: "starrocks-default"
      username: "root"
      host: "starrocks.example.com"
      port: 9030                    # optional, defaults to 9030 (FE MySQL protocol port)
      password: "XXXXXXXXXX"        # optional
      database: "analytics"         # optional
      ssl: "true"                   # optional — "true" or "skip-verify"

The ssl setting controls SQL connections, including native assets and seeds. For ingestion into an HTTPS Stream Load endpoint, configure http_scheme: https and its http_port separately; see StarRocks destination connections.

StarRocks Assets ​

starrocks.sql ​

Executes a materialized StarRocks SQL asset.

bruin-sql
/* @bruin
name: analytics.example
type: starrocks.sql
materialization:
    type: table
@bruin */

SELECT
    id,
    country,
    name
FROM staging.customers

Supported table materialization strategies:

  • create+replace
  • append
  • delete+insert
  • merge
  • truncate+insert
  • time_interval
  • ddl

View materialization is also supported. For local and single-node StarRocks clusters, Bruin creates StarRocks-managed tables with PROPERTIES ("replication_num" = "1"). delete+insert and seeds replace the table atomically with StarRocks' ALTER TABLE ... SWAP WITH ...; delete+insert builds its replacement with CREATE TABLE ... LIKE the target, so the table keeps its definition.

truncate+insert runs INSERT OVERWRITE, which StarRocks applies atomically and which keeps the table's definition, including changes made outside Bruin. When the table does not exist yet, Bruin creates it on the first run with the layout below. append, truncate+insert, delete+insert and time_interval insert into the existing table. When Bruin creates the table from typed columns, which happens when the asset declares columns and sets starrocks.keys, starrocks.table_model, starrocks.buckets, cluster_by or partition_by, these strategies (and merge) name those columns in the insert, so the query returns them in the declared order even though the table puts its key columns first. Otherwise, the query has to return the table's columns in order. After changing the columns, run the asset once with --full-refresh to rebuild the table.

Table layout ​

Distribution and partitioning are taken from the standard materialization fields, so they work the same way as on the other platforms:

  • materialization.cluster_by → DISTRIBUTED BY HASH(...) (defaults to the key columns)
  • materialization.partition_by → PARTITION BY (columns such as event_date become PARTITION BY (event_date); an expression such as date_trunc('day', event_date) is emitted as written)

partition_by is emitted verbatim so that expressions work, so it is not automatically backtick-quoted. If you partition on a single column whose name is a StarRocks reserved word (e.g. date, value, key), quote it yourself: partition_by: "date".

StarRocks-specific layout that has no materialization equivalent is declared under starrocks:

yaml
materialization:
  type: table
  strategy: create+replace
  cluster_by: [account_id]          # DISTRIBUTED BY HASH(account_id)
  partition_by: event_date          # PARTITION BY (event_date)

starrocks:
  table_model: primary_key          # duplicate_key | unique_key | primary_key
  keys: [account_id]                # key columns, in order
  buckets: 8                        # StarRocks picks the number when unset
  properties:
    replication_num: "1"

keys sets the columns of the table's key clause (DUPLICATE KEY, UNIQUE KEY or PRIMARY KEY). Without it, unique and primary key tables use the columns marked primary_key: true, and duplicate key tables use the first declared column, or let StarRocks choose when the asset declares no columns. When neither cluster_by nor a key is set, buckets alone gives DISTRIBUTED BY RANDOM BUCKETS n.

When the asset declares typed columns and any of these settings, Bruin creates the table with a typed CREATE TABLE and the key columns first, then inserts the query. Otherwise it runs CREATE TABLE ... AS SELECT with the same clauses. In that case:

  • the key columns have to be the first columns the query returns, in key order, because StarRocks requires the key to lead the table;
  • unique_key tables need typed columns, because StarRocks cannot create them from a query.

For example, a duplicate key table keyed and distributed on one column, overwritten on every run:

yaml
name: analytics.product_names
type: starrocks.sql
materialization:
  type: table
  strategy: truncate+insert
  cluster_by: [product_code]
starrocks:
  table_model: duplicate_key
  keys: [product_code]
  buckets: 8
  properties:
    compression: LZ4
    replication_num: "1"

Merge materialization ​

StarRocks has no MERGE INTO statement. Bruin implements merge with a StarRocks PRIMARY KEY table: matching rows are replaced and new rows inserted by a plain INSERT. Bruin infers starrocks.table_model: primary_key for merge assets, creates the table if it does not exist, and upserts on the primary key.

Merge assets must declare typed columns and their key, either with primary_key: true columns or with starrocks.keys. Per-column merge_sql expressions are not supported (StarRocks upserts whole rows on the primary key) — encode that logic in the asset query instead.

bruin-sql
/* @bruin
name: analytics.accounts
type: starrocks.sql
materialization:
    type: table
    strategy: merge

columns:
  - name: account_id
    type: BIGINT
    primary_key: true
  - name: status
    type: VARCHAR(32)
    update_on_merge: true
@bruin */

SELECT account_id, status
FROM staging.accounts

starrocks.seed ​

Loads a local CSV file into StarRocks.

yaml
name: analytics.seed_contacts
type: starrocks.seed

columns:
  - name: name
    type: STRING
  - name: channel
    type: STRING

parameters:
  path: seed.csv
  file_type: csv

starrocks.sensor.table ​

Waits until a StarRocks table exists.

yaml
name: analytics.wait_for_daily_summary
type: starrocks.sensor.table
parameters:
    table: analytics.daily_summary
    poke_interval: 30

starrocks.sensor.query ​

Waits until a StarRocks query returns at least one row.

yaml
name: analytics.wait_for_orders
type: starrocks.sensor.query
parameters:
    query: SELECT 1 FROM analytics.orders WHERE order_date = "{{ end_date }}" LIMIT 1

starrocks.source ​

Defines an existing StarRocks table as a source asset for lineage and documentation. These assets don't execute, but their quality checks do.

yaml
name: analytics.raw_orders
type: starrocks.source

columns:
  - name: order_id
    type: BIGINT