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

# Google BigQuery

> Learn how to setup an import job using Google BigQuery

### Step 1 - Start the Data Upload Wizard

Navigate to the 'Upload Data' page on the left navigation bar in the Arize platform. From there, select the 'Google BQ' card or navigate to the Data Warehouse tab to start a new table import job to begin **a new table import job.**

**Storage Selection: Google BQ**

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/a2231c39-image.jpeg" />
</Frame>

### Step 2 - Input the Project ID, Dataset, and Table / View

Locate the Project ID, Dataset, and Table *or* View name of the table/view you would like to sync from Google BigQuery.

* The GBQ Project ID is a unique identifier for a project. See [here](https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects) for steps on how to retrieve this ID.

* The dataset and table name correspond to the path where your table is located

<Frame caption="Console view to find Project ID, Dataset name and Table/View name">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/8fc4ced8-image.jpeg" />
</Frame>

Add your Table ID Arize. Arize will automatically parse your Dataset, Table Name, and GCP Project ID.

<Frame caption="Example TableID">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/e731f3da-image.jpeg" />
</Frame>

### Step 3 - Grant Access To Your Dataset, Table, or View

Tag your dataset/table/view with the `arize-ingestion-key` and the provided label value using the steps below. For more details, see docs on [Adding labels to resources](https://cloud.google.com/bigquery/docs/adding-labels) for BigQuery.

\*\*In Arize UI: \*\*Copy `arize-ingestion-key` value

<Frame caption="Copy Arize Ingestion Key">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/5e5daed7-image.jpeg" />
</Frame>

<Info>
  You can grant access to [**a single table or view**](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#grant-access-to-a-table-view)**or **[**all the tables/views in a dataset**](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#grant-access-to-an-entire-dataset)**.**

  Consider creating an [authorized view](https://cloud.google.com/bigquery/docs/authorized-views) if you don't want to grant access to the underlying tables, or granting access to each underlying table is too cumbersome.
</Info>

<Columns cols={2}>
  <Card>[**Grant Access To A Table/View**](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#grant-access-to-a-table-view)</Card>
  <Card>[**Grant Access To An Entire Dataset**](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#grant-access-to-an-entire-dataset)</Card>
</Columns>

#### Grant Access To A Table/View

<Tabs>
  <Tab title="From UI">
    1. **In Google Cloud console**: Navigate to the BigQuery SQL Workspace

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/228982bd-image.jpeg" />
    </Frame>

    2. Select the desired table or view, navigate to the **Details** tab and click "Edit Details". Under the **Labels** section, click "Add Labels". Add the following label:

       * Key as "**arize-ingestion-key**\*\*\*"\*\*\*

       * Value\* *as the*\*\* ***arize-ingestion-key*** value \*\*\*from the Arize UI

           <Frame caption="">
             <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/c6aacfdc-image.jpeg" />
           </Frame>

           <Frame caption="">
             <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/f903064a-image.jpeg" />
           </Frame>

    3. Grant the `roles/bigquery.jobUser` role to our service account. Go to the IAM page and click "Grant Access"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/7eb00334-image.jpeg" />
    </Frame>

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/b118baa1-image.jpeg" />
    </Frame>

    Add Arize service account as "Principal" with "BigQuery Job User" role

    * Navigate to your table/view from the Bigquery SQL Explorer page.

    * Select "Share" and click on "Permissions"

          <Frame caption="">
            <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/a15d672b-image.jpeg" />
          </Frame>

    * Click "Add Principal"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/0c06e396-image.jpeg" />
    </Frame>

    * Add our service account: `fileimporter@production-269901.iam.gserviceaccount.com` as a BigQuery Data Viewer, and click "Save"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/7ebe59a9-image.jpeg" />
    </Frame>

    * For a view, you must grant access to \*\*all underlying tables, \*\*so you must repeat these step for all the underlying tables.

    <Info>
      For more details: see the official documentation for granting access [here](https://cloud.google.com/bigquery/docs/control-access-to-resources-iam#grant_access_to_a_table_or_view)
    </Info>

    4. [Navigate to Step 4 - Configure your model and define your table’s schema](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#step-4-configure-your-model-and-define-your-tables-schema)
  </Tab>

  <Tab title="From CLI">
    You can create a cloud shell instance from the UI to run the following commands

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/77fbbaed-image.jpeg" />
    </Frame>

    1. Add the `arize-ingestion-key` key from the Arize UI as a label on the dataset

    ```ruby theme={null}
    bq update --set_label arize-ingestion-key:${KEY_FROM_UI} ${PROJECT_ID}:${DATASET}
    ```

    2. Grant the `roles/bigquery.jobUser` role to the Arize service account.

    ```ruby theme={null}
    gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:fileimporter@production-269901.iam.gserviceaccount.com --role=roles/bigquery.jobUser
    ```

    3. To grant the `roles/bigquery.dataViewer` role to the Arize service account your table or view

       * Table:

       ```powershell theme={null}
        bq add-iam-policy-binding \
        --member='serviceAccount:fileimporter@production-269901.iam.gserviceaccount.com' \
        --role='roles/bigquery.dataViewer' \
         ${PROJECT_ID}:${DATASET}.${TABLE}
       ```

       * View: See the Google BigQuery [guide to grant access to a view](https://cloud.google.com/bigquery/docs/authorized-views#authorize_a_view) and navigate to the tab `bq`.

    4. [Navigate to Step 4 - Configure your model and define your table’s schema](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#step-4-configure-your-model-and-define-your-tables-schema)
  </Tab>
</Tabs>

#### Grant Access To An Entire Dataset:

<Tabs>
  <Tab title="From UI">
    1. **In Google Cloud console**: Navigate to the BigQuery SQL Workspace

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/228982bd-image.jpeg" />
    </Frame>

    2. Select the desired dataset, and click "Edit Details". Under the **Labels** section, click "Add Labels". Add the following label:

       * Key as "**arize-ingestion-key**\*\*\*"\*\*\*

       * Value\* *as the*\*\* ***arize-ingestion-key*** *****value***** \*\*\*copied from the Arize UI

       *     <Frame caption="">
               <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/2973045d-image.jpeg" />
             </Frame>

           <Frame caption="">
             <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/8bd7e0ef-image.jpeg" />
           </Frame>

    3. Grant the `roles/bigquery.jobUser` role to the Arize service account. Go to the IAM page and click "Grant Access"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/7eb00334-image.jpeg" />
    </Frame>

    * Navigate to your dataset from the Bigquery SQL Explorer page.

    * Select "Sharing" and click on "Permissions"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/2f116f2a-image.jpeg" />
    </Frame>

    * Click "Add Principal"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/430d340f-image.jpeg" />
    </Frame>

    * Add Arize service account: `fileimporter@production-269901.iam.gserviceaccount.com` as a BigQuery Data Viewer, and click "Save"

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/4178e135-image.jpeg" />
    </Frame>

    <Info>
      For additional details: see the official documentation for granting access [here](https://cloud.google.com/bigquery/docs/control-access-to-resources-iam#grant_access_to_a_dataset)
    </Info>

    4. [Navigate to Step 4 - Configure your model and define your table’s schema](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#step-4-configure-your-model-and-define-your-tables-schema)
  </Tab>

  <Tab title="From CLI">
    You can create a cloud shell instance from the UI to run the following commands

    <Frame caption="">
      <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/e9853424-image.jpeg" />
    </Frame>

    1. Add the `arize-ingestion-key` key from the Arize UI as a label on the dataset

    ```ruby theme={null}
    bq update --set_label arize-ingestion-key:${KEY_FROM_UI} ${PROJECT_ID}:${DATASET}
    ```

    2. Grant the `roles/bigquery.jobUser` role to the Arize service account.

    ```ruby theme={null}
    gcloud projects add-iam-policy-binding ${PROJECT_ID} --member=serviceAccount:fileimporter@production-269901.iam.gserviceaccount.com --role=roles/bigquery.jobUser
    ```

    3. To grant the `roles/bigquery.dataViewer` role to the Arize service account on your dataset, see the BigQuery [guide to grant access to a dataset](https://cloud.google.com/bigquery/docs/control-access-to-resources-iam#grant_access_to_a_dataset) and navigate to the tab `bq`.

    4. [Navigate to Step 4 - Configure your model and define your table’s schema](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery#step-4-configure-your-model-and-define-your-tables-schema)
  </Tab>
</Tabs>

### Step 4 - Configure Your Model And Define Your Table’s Schema

Match your model schema to your [model type](/ax/machine-learning/machine-learning/use-cases-ml) and define your model schema through the form input or a json schema.

<Frame caption="Set up model configurations">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/1c5938c6-image.jpeg" />
</Frame>

<Frame caption="Map your table using a form">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/6ca62695-image.jpeg" />
</Frame>

<Frame caption="Map your table using a JSON schema">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/f39899d4-image.jpeg" />
</Frame>

Learn more about Schema fields [here](/ax/machine-learning/machine-learning/concepts-ml/model-schema-reference#list-of-model-schema-fields-for-data-ingestion-integrations).

Once finished, Arize will begin querying your table and ingesting your records as model inferences.

### Step 4b. Validate Model Schema

Once you fill in your applicable predictions, actuals, and model inputs, click 'Validate Schema' to visualize your model schema in the Arize UI. Check that your column names and corresponding data match for a successful import job.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/a0acecf2-image.jpeg" />
</Frame>

### Step 5 - Add Model Data To The Table Or View

Arize will run queries to ingest records from your table based on your configured **refresh interval**.

### Step 6 - Check your Table Import Job

Arize will attempt a dry run to validate your job for any access, schema, or record-level errors. If the dry run is successful, you can proceed to create the import job.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/1abf1022-image.jpeg" />
</Frame>

From there, you will be taken to the 'Job Status' tab where you can see the status of your import jobs.

<Frame caption="Table of your import jobs">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/c82b2347-image.jpeg" />
</Frame>

**All active jobs** will regularly sync new data from your data source with Arize. You can view the job details and import progress by clicking on the job ID, which reveals more information about the job.

<Frame caption="Audit trail of queries run on your table">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/81e9b67b-image.jpeg" />
</Frame>

### Step 6.5 Pause or Delete An Import Job

To pause or edit your table schema, click on 'Job Options'.

* **Delete** a job if it is no longer needed or if you made an error connecting to the wrong bucket. This will set your job status as 'deleted' in Arize.

* **Pause** a job if you have a set cadence to update your table. This way, you can 'start job' when you know there will be new data to reduce query costs. This will set your job status as 'inactive' in Arize.

<Frame caption="Job Status tab showing job listings">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/366c7797-image.jpeg" />
</Frame>

### Step 7 - Troubleshooting An Import Job

An import job may run into a few problems. Use the dry run and job details UI to troubleshoot and quickly resolve data ingestion issues.

#### Validation Errors

If there is an error validating a file or table against the model schema, Arize will surface an **actionable** error message. From there, click on the 'Fix Schema' button to adjust your model schema.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/8b2a6365-image.jpeg" />
</Frame>

#### Dry Run File/Table Passes But The Job Fails

If your dry run is successful, but your job fails, click on the job ID to view the\*\* job details\*\*. This uncovers job details such as information about the file path or query id, the last import job, potential errors, and error locations.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/e41ba027-image.jpeg" />
</Frame>

Within the Job Details section, you can select More Details on a specific query to view the start time and end time that was used in that query. The query start time represents the max value of the [change\_timestamp](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery/google-bigquery-faq#how-do-i-update-fix-a-row-that-failed-to-ingest) based on the previous query, and the query end time is the current day/time that the query was run. The query start time will then be updated after each query to reflect the current max `change_timestamp`. This can help debug issues specifically related to the `change_timestamp` field.

<Frame caption="">
  <img src="https://storage.googleapis.com/arize-phoenix-assets/assets/images/arize-docs-images/b95adf6a-image.jpeg" />
</Frame>

Once you've identified the job failure point, append the edited row to the end of your table with an updated [change\_timestamp](/ax/machine-learning/machine-learning/integrations-ml/google-bigquery/google-bigquery-faq#how-do-i-update-fix-a-row-that-failed-to-ingest) value.
