> ## 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 Google BigQuery

> This guide describes how to sink data from RisingWave to Google BigQuery.

[BigQuery](https://cloud.google.com/bigquery?hl=en) is Google's fully managed data warehouse and data analytics platform, capable of handling and analyzing large volumes of data as it is highly scalable.

You can test out this process on your own device by using the `big-query-sink` demo in the [integration\_test directory](https://github.com/risingwavelabs/risingwave/tree/main/integration%5Ftests) of the RisingWave repository.

<Tip>
  **PREMIUM FEATURE**

  This is a premium feature. For a comprehensive overview of all premium features and their usage, please see [RisingWave premium features](/get-started/premium-features).
</Tip>

## Prerequisites

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

* The BigQuery table you want to sink to is accessible from RisingWave.
* Ensure you have an upstream materialized view or table 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='bigquery',
   connector_parameter = 'value', ...
);
```

## Parameters

| Parameter Names                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| :---------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *sink\_name*                        | Name of the sink to be created.                                                                                                                                                                                                                                                                                                                                                                                                                          |
| *sink\_from*                        | A clause that specifies the direct source from which data will be output. `sink_from` can be a materialized view or a table. Either this clause or `select_query` query must be specified.                                                                                                                                                                                                                                                               |
| AS *select\_query*                  | A SELECT query that specifies the data to be output to the sink. Either this query or a `sink_from` clause must be specified. See [SELECT](/sql/commands/sql-select) for the syntax and examples of the SELECT command.                                                                                                                                                                                                                                  |
| type                                | **Required**. Data format. Allowed formats: <ul><li>`append-only`: Output data with insert operations.</li><li>`upsert`: For this type, you need to set corresponding permissions and primary keys based on the [Document of BigQuery](https://cloud.google.com/bigquery/docs/change-data-capture).</li></ul>                                                                                                                                            |
| force\_append\_only                 | **Optional**. If true, forces the sink to be append-only, even if it cannot be.                                                                                                                                                                                                                                                                                                                                                                          |
| bigquery.local.path                 | **Optional**. The file path leading to the JSON key file located on your local machine. Details can be found in [Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) under your Google Cloud account. At least one of `bigquery.credentials`, `bigquery.local.path`, or `bigquery.s3.path` must be specified.                                                                                                                  |
| bigquery.s3.path                    | **Optional**. The file path leading to the JSON key file located in S3. Details can be found in [Service Accounts](https://console.cloud.google.com/iam-admin/serviceaccounts) under your Google Cloud account. At least one of `bigquery.credentials`, `bigquery.local.path`, or `bigquery.s3.path` must be specified. If this parameter is used, `aws.credentials.access_key_id`, `aws.credentials.secret_access_key`, and `region` are also required. |
| bigquery.project                    | **Required**. The BigQuery project ID.                                                                                                                                                                                                                                                                                                                                                                                                                   |
| bigquery.dataset                    | **Required**. The BigQuery dataset ID.                                                                                                                                                                                                                                                                                                                                                                                                                   |
| bigquery.table                      | **Required**. The BigQuery table you want to sink to.                                                                                                                                                                                                                                                                                                                                                                                                    |
| bigquery.credentials                | **Optional**. Enter the JSON key credentials as a string. Both plain JSON and Base64-encoded JSON are accepted; Base64 is recommended for inline use to avoid escaping issues. At least one of `bigquery.credentials`, `bigquery.local.path`, or `bigquery.s3.path` must be specified.                                                                                                                                                                   |
| bigquery.retry\_times               | **Optional**. The number of times the system should retry a BigQuery insert operation before ultimately returning an error. Defaults to 5.                                                                                                                                                                                                                                                                                                               |
| auto\_create                        | **Optional**. Defaults to false. If true, a new table will be automatically created in BigQuery when the specified table is not found.                                                                                                                                                                                                                                                                                                                   |
| aws.credentials.access\_key\_id     | **Optional**. The access key for accessing the S3 file storing the JSON key. Required when `bigquery.s3.path` is specified.                                                                                                                                                                                                                                                                                                                              |
| aws.credentials.secret\_access\_key | **Optional**. The secret access key for accessing the S3 file storing the JSON key. Required when `bigquery.s3.path` is specified.                                                                                                                                                                                                                                                                                                                       |
| region                              | **Optional**. The AWS region of the S3 file storing the JSON key. Required when `bigquery.s3.path` is specified.                                                                                                                                                                                                                                                                                                                                         |

## Examples

RisingWave supports three ways to provide the Google Cloud service account JSON key for authenticating with BigQuery.

**Option 1: Inline credentials string**

```sql Example using inline credentials theme={null}
CREATE SINK big_query_sink_credentials
FROM mv1
WITH (
    connector = 'bigquery',
    type = 'append-only',
    bigquery.credentials= '${base64_encoded_service_account_json}',
    bigquery.project= '${project_id}',
    bigquery.dataset= '${dataset_id}',
    bigquery.table= '${table_id}',
    force_append_only='true'
);
```

**Option 2: Local JSON key file**

```sql Example using a local JSON key file theme={null}
CREATE SINK big_query_sink_local
FROM mv1
WITH (
    connector = 'bigquery',
    type = 'append-only',
    bigquery.local.path= '${bigquery_service_account_json_path}',
    bigquery.project= '${project_id}',
    bigquery.dataset= '${dataset_id}',
    bigquery.table= '${table_id}',
    force_append_only='true'
);
```

**Option 3: JSON key file stored in S3**

When the JSON key file is stored in S3, you must also provide the AWS credentials and region to access it.

```sql Example using a JSON key file stored in S3 theme={null}
CREATE SINK big_query_sink_s3
FROM mv1
WITH (
    connector = 'bigquery',
    type = 'append-only',
    bigquery.s3.path= '${s3_service_account_json_path}',
    bigquery.project= '${project_id}',
    bigquery.dataset= '${dataset_id}',
    bigquery.table= '${table_id}',
    aws.credentials.access_key_id = '${aws_access_key}',
    aws.credentials.secret_access_key = '${aws_secret_access}',
    region = '${aws_region}',
    force_append_only='true'
);
```

## Data type mapping

| RisingWave Data Type        | BigQuery Data Type |
| :-------------------------- | :----------------- |
| boolean                     | bool               |
| smallint                    | int64              |
| integer                     | int64              |
| bigint                      | int64              |
| real                        | unsupported        |
| double precision            | float64            |
| numeric                     | numeric            |
| date                        | date               |
| character varying (varchar) | string             |
| time without time zone      | time               |
| timestamp without time zone | datetime           |
| timestamp with time zone    | timestamp          |
| interval                    | interval           |
| struct                      | struct             |
| array                       | array              |
| bytea                       | bytes              |
| JSONB                       | JSON               |
| serial                      | int64              |
