> ## Documentation Index
> Fetch the complete documentation index at: https://docs.risingwave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sink data from RisingWave to StarRocks

> This guide describes how to sink data from RisingWave to StarRocks.

StarRocks is an open-source, massively parallel processing (MPP) database. For details on how to get started with StarRocks, see the [Quick start](https://docs.starrocks.io/docs/quick%5Fstart/) guide.

The StarRocks stream load does not support sinking `struct` type.

## Prerequisites

Before sinking data from RisingWave to StarRocks, please ensure the following:

* The StarRocks database you want to sink to is accessible from RisingWave.
* Ensure you have an upstream materialized view or source in RisingWave that you can sink data from.

## Syntax

```sql theme={null}
CREATE SINK [ IF NOT EXISTS ] sink_name
[FROM sink_from | AS select_query]
WITH (
   connector='starrocks',
   connector_parameter = 'value', ...
);
```

## Parameters

All parameters are required unless specified otherwise.

| Parameter names                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| :-------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| starrocks.host                    | The StarRocks host address.                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| starrocks.query\_port             | The port to the MySQL server of the StarRocks frontend.                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| starrocks.http\_port              | The port to the HTTP server of the StarRocks frontend.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| starrocks.user                    | The user name used to access the StarRocks database.                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| starrocks.password                | The password associated with the user.                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| starrocks.database                | The StarRocks database where the target table is located                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| starrocks.table                   | The StarRocks table you want to sink data to.                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| starrocks.partial\_update         | **Optional**. Set it to `true` to improve performance when you need to update many rows but only change a few columns in each row.                                                                                                                                                                                                                                                                                                                                                                 |
| starrocks.max\_batch\_size\_bytes | **Optional**. The maximum size in bytes for each StarRocks stream load request payload. Set it to a positive integer to have RisingWave split requests by encoded JSON payload size before sending them to StarRocks.                                                                                                                                                                                                                                                                              |
| type                              | Data format. Allowed formats:<ul><li> `append-only`: Output data with insert operations.</li><li> `upsert`: Output data as a chagelog stream. In StarRocks, Primary Key table must be selected. </li></ul>                                                                                                                                                                                                                                                                                         |
| force\_append\_only               | If `true`, forces the sink to be append-only, even if it cannot be.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| primary\_key                      | Required if type is `upsert`. The primary key of the downstream table.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| commit\_checkpoint\_interval      | **Optional**. Commit every N checkpoints (N > 0). Default value is 10. The behavior of this field also depends on the `sink_decouple` setting:<ul><li>If `sink_decouple` is true (the default), the default value of `commit_checkpoint_interval` is 10.</li> <li>If `sink_decouple` is set to false, the default value of `commit_checkpoint_interval` is 1.</li> <li>If `sink_decouple` is set to false and `commit_checkpoint_interval` is set to larger than 1, an error will occur.</li></ul> |

## Examples

Assume we have a materialized view, `bhv_mv`.

```sql theme={null}
CREATE SINK bhv_starrocks_sink
FROM bhv_mv WITH (
    connector = 'starrocks',
    type = 'append-only',
    starrocks.host = 'starrocks-fe',
    starrocks.mysqlport = '9030',
    starrocks.httpport = '8030',
    starrocks.user = 'users',
    starrocks.password = '123456',
    starrocks.database = 'demo',
    starrocks.table = 'demo_bhv_table',
    force_append_only='true'
);
```

## Data type mapping

The following table shows the corresponding data type in RisingWave that should be specified when creating a sink. For details on native RisingWave data types, see [Overview of data types](/sql/data-types/overview).

| StarRocks type | RisingWave type                                                                                   |
| :------------- | :------------------------------------------------------------------------------------------------ |
| BOOLEAN        | BOOLEAN                                                                                           |
| SMALLINT       | SMALLINT                                                                                          |
| INT            | INTEGER                                                                                           |
| BIGINT         | BIGINT                                                                                            |
| FLOAT          | REAL                                                                                              |
| DOUBLE         | DOUBLE                                                                                            |
| DECIMAL        | DECIMAL                                                                                           |
| DATE           | DATE                                                                                              |
| VARCHAR        | VARCHAR                                                                                           |
| No support     | TIME                                                                                              |
| DATETIME       | TIMESTAMP WITHOUT TIME ZONE                                                                       |
| No support     | TIMESTAMP WITH TIME ZONE（Can be converted to timestamp in RisingWave then sinked into StarRocks ） |
| No support     | INTERVAL                                                                                          |
| No support     | STRUCT                                                                                            |
| ARRAY          | ARRAY                                                                                             |
| No support     | BYTEA                                                                                             |
| JSON           | JSONB                                                                                             |
| BIGINT         | SERIAL                                                                                            |

If a decimal value is out of bounds or represents `inf`, `-inf`, or `nan`, RisingWave will insert null values.
