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

# BigQuery

## Overview

[Google BigQuery](https://cloud.google.com/bigquery) is a fully managed, serverless data warehouse that enables scalable analysis over large datasets. In Zenskar, you can use BigQuery as a **data source** for billable metrics and dashboards.

***

## Prerequisites

* [Enable BigQuery API in your GCP](https://cloud.google.com/apis/docs/enable-disable-apis) before connecting it to Zenskar. [You can enable BigQuery API directly from your project too.](https://console.cloud.google.com/flows/enableapi?apiid=bigquery.googleapis.com).
* [Create a service account](https://cloud.google.com/iam/docs/creating-managing-service-accounts).
* [Add the Service Account as a **Member** in your GCP account with the **BigQuery User** role](https://cloud.google.com/iam/docs/granting-changing-revoking-access#granting-console).
* Similarly, assign the **BigQuery Data Editor** role to the Service Account.

<Callout icon="📖" theme="default">
  We highly recommend that you create a Service Account exclusive to Zenskar for ease of permission and auditing. However, you can use a pre-existing Service Account that has the correct permissions.
</Callout>

### Create and manage a Service Account key in Google Cloud Project

* [Service Account keys](https://cloud.google.com/iam/docs/service-accounts#service_account_keys) are used to authenticate as Google Service Accounts. Zenskar requires the Service Account keys to leverage the role-based permissions you granted to the Service Account in the previous section.
* [Create and manage a Service Account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys). Ensure the following:
  * **Create your key in JSON format**.
  * Download the key immediately.
* Google will not allow you to see the contents of the key once you navigate away.

<Callout icon="⚠️" theme="warn">
  Delete the downloaded key file after setup for security.
</Callout>

***

## Set up a BigQuery data-source connector via Zenskar dashboard

1. Log into your Zenskar dashboard.
2. In the left side bar, click **Usage** > **Data Sources**.
3. In the top-right corner, click **+ ADD DATA SOURCE**.
4. On the **Add New Data Source** page, [configure the BigQuery connector](https://docs.zenskar.com/docs/data-source-connector-for-bigquery#connector-configuration-1).
5. Click on the **SAVE SOURCE** button.

### Connector configuration

#### General configuration

| Field           | Description                                 | Required |
| :-------------- | :------------------------------------------ | :------- |
| **Source Name** | Enter a unique name for this data source.   | Yes      |
| **Source Type** | Select **BigQuery** from the dropdown menu. | Yes      |

#### Connector configuration

| Field                | Description                                                                                                                       | Required |
| :------------------- | :-------------------------------------------------------------------------------------------------------------------------------- | :------- |
| **Project ID**       | The ID of your Google Cloud project that contains the BigQuery datasets.                                                          | Yes      |
| **Dataset ID**       | The dataset you want to query.                                                                                                    | Yes      |
| **Location**         | The [geographic location of your BigQuery dataset](https://cloud.google.com/bigquery/docs/locations) (for example, `US` or `EU`). | Yes      |
| **Credentials JSON** | Paste the contents of your **Service Account Key** (JSON format).                                                                 | Yes      |

#### Data source access mode (read-only)

Zenskar queries data directly from BigQuery without syncing it to Zenskar’s data infrastructure. This option is:

* Ideal for **large databases** (more than 30 GB)
* Suitable for **real-time data access**
* **No sync waiting time**

You will be able to browse and query tables from this BigQuery source in the **Data Navigator** while creating aggregates.

***

## Set up a BigQuery data-source connector via API

<Cards columns={0}>
  <Card title="Refer to the create data-source connector API reference." href="https://www.zenskar.com/reference/create-data-source-connector" icon="fa-info" target="_blank" />
</Cards>

<Callout icon="💡" theme="default">
  The `connector_config` object is the only part of the request that differs across connector types (such as BigQuery, Snowflake, or Redshift). The [create data-source connector API reference](https://www.zenskar.com/reference/create-data-source-connector) provides a generic overview, while this document explains the BigQuery-specific structure of `connector_config`.
</Callout>

### Request example

```curl theme={null}
curl --location 'https://api.zenskar.com/datasources' \
  -H 'x-api-key: <your-api-key>' \
  -H 'apiversion: 20240301' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "abc",
    "connector_type": "BigQuery",
    "destination": "BigQuery",
    "status": "active",
    "connector_config": {
      "project_id": "my-test-project-84030",
      "dataset_id": "abc123",
      "location": "US",
      "credentials_json": "{ \"type\": \"service_account\", \"project_id\": \"my-test-project-84030\", \"private_key_id\": \"0533306f55057\", \"private_key\": \"-----BEGIN PRIVATE KEY-----\\t/YgHKB4tH\\n-----END PRIVATE KEY-----\\n\", \"client_email\": \"example@my-test-project-84030.iam.gserviceaccount.com\", \"token_uri\": \"https://oauth2.googleapis.com/token\" }"
    },
    "source_definition_id": "bfd1ddf8-ae8a-4620-b1d7-55597d2ba08c",
    "remote_conn": true
  }'
```

#### &#x20;BigQuery-specific connector configuration

The `connector_config` object contains configuration fields specific to the BigQuery data source.

| Field              | Description                                                                                                                                                                 | Required |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `project_id`       | The unique ID of your Google Cloud project that contains the BigQuery datasets.                                                                                             | Yes      |
| `dataset_id`       | The dataset name (for example, `abc123`). **Do not** include the project ID prefix (such as `my-test-project-84030.abc123`). The project ID is already supplied separately. | Yes      |
| `location`         | The geographic location of your BigQuery dataset (for example, `US` or `EU`).                                                                                               | Yes      |
| `credentials_json` | The complete contents of your Service Account key, formatted as a **stringified JSON** (escaped quotes and newlines).                                                       | Yes      |

<Callout icon="💡" theme="default">
  * Some users may specify `dataset_id` in the format `<project_id>.<dataset_id>` (for example, `my-test-project-84030.abc123`), which is valid in BigQuery but **not supported in Zenskar**. Pass only the dataset name (`abc123`), as `project_id` is already handled separately.
  * Ensure that the Service Account used has the **BigQuery User** and **BigQuery Data Editor** roles.
  * Zenskar supports only **JSON-format** Service Account keys.
</Callout>

***

## Notes

<Callout icon="📘" theme="info">
  Zenskar does **not modify** your existing BigQuery data or schema.
</Callout>

<Callout icon="📘" theme="info">
  Queries are executed using your service account’s permissions.
</Callout>

<Callout icon="📘" theme="info">
  For best performance, use partitioned or clustered tables when working with large datasets.
</Callout>

<br />
