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

# Set up a Snowflake data warehouse

export const Comments = ({children}) => {
  return <div class="my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border border-zinc-500/20 bg-zinc-50/50 dark:border-zinc-500/30 dark:bg-zinc-500/10" data-callout-type="comments">
      <div class="w-4">
        <svg width="14" height="14" viewBox="0 0 640 640" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" aria-label="Comments">
            <path d="M320 112C434.9 112 528 205.1 528 320C528 434.9 434.9 528 320 528C205.1 528 112 434.9 112 320C112 205.1 205.1 112 320 112zM320 576C461.4 576 576 461.4 576 320C576 178.6 461.4 64 320 64C178.6 64 64 178.6 64 320C64 461.4 178.6 576 320 576zM280 400C266.7 400 256 410.7 256 424C256 437.3 266.7 448 280 448L360 448C373.3 448 384 437.3 384 424C384 410.7 373.3 400 360 400L352 400L352 312C352 298.7 341.3 288 328 288L280 288C266.7 288 256 298.7 256 312C256 325.3 266.7 336 280 336L304 336L304 400L280 400zM320 256C337.7 256 352 241.7 352 224C352 206.3 337.7 192 320 192C302.3 192 288 206.3 288 224C288 241.7 302.3 256 320 256z" />
        </svg>
      </div>
      <div class="text-sm prose min-w-0 w-full">
        {children}
      </div>
    </div>;
};

This tutorial walks you through setting up a test Snowflake data warehouse and connecting it to Anaconda Platform so you can query data from your workstations and Metaflow flows.

<Note>
  Creating a resource integration requires an administrator role. If you do not have administrator access, ask your administrator to create the integration before you begin.
</Note>

By the end of this tutorial, you will have:

* A Snowflake user, role, database, and schema configured for the platform
* A Snowflake integration registered on the platform
* A workstation notebook that reads data from Snowflake
* A Metaflow flow that queries Snowflake

## Set up Snowflake resources

Create a Snowflake user and role that can read and write to a database. You can use an existing user, role, and database if you have them. Otherwise, use the following template to create the minimal components:

<Accordion title="Minimal Snowflake setup SQL">
  ```sql theme={null}
  -- 1. Create a role
  CREATE ROLE IF NOT EXISTS <YOUR_ROLE>;

  -- 2. Create a user and set default DB/schema
  CREATE USER IF NOT EXISTS <YOUR_USER>
    PASSWORD = 'StrongPasswordHere1!'
    LOGIN_NAME = '<YOUR_USER>'
    MUST_CHANGE_PASSWORD = FALSE
    DEFAULT_ROLE = <YOUR_ROLE>
    DEFAULT_WAREHOUSE = <YOUR_WAREHOUSE>
    DEFAULT_NAMESPACE = <YOUR_DB>.<YOUR_SCHEMA>
    COMMENT = 'User for Demo';

  -- 3. Grant the role to the user
  GRANT ROLE <YOUR_ROLE> TO USER <YOUR_USER>;

  -- 4. Grant usage on a warehouse to the role
  GRANT USAGE ON WAREHOUSE <YOUR_WAREHOUSE> TO ROLE <YOUR_ROLE>;

  -- 5. Create a test database and schema for the user to read/write
  CREATE DATABASE IF NOT EXISTS <YOUR_DB> COMMENT = 'Database for Demo';
  CREATE SCHEMA IF NOT EXISTS <YOUR_DB>.<YOUR_SCHEMA> COMMENT = 'Schema for Demo';

  -- 6. Grant privileges on the new database/schema to the role
  GRANT ALL PRIVILEGES ON DATABASE <YOUR_DB> TO ROLE <YOUR_ROLE>;

  -- 7. Grant privileges on the schema
  GRANT ALL PRIVILEGES ON SCHEMA <YOUR_DB>.<YOUR_SCHEMA> TO ROLE <YOUR_ROLE>;

  -- (Optional) Grant privileges on future objects in the schema
  -- so that the role automatically gets read/write privileges
  -- for newly created tables or views
  GRANT ALL PRIVILEGES ON FUTURE TABLES IN SCHEMA <YOUR_DB>.<YOUR_SCHEMA> TO ROLE <YOUR_ROLE>;
  GRANT ALL PRIVILEGES ON FUTURE VIEWS IN SCHEMA <YOUR_DB>.<YOUR_SCHEMA> TO ROLE <YOUR_ROLE>;
  ```

  <Comments>
    Replace \<YOUR\_ROLE> with the name of the Snowflake role to create.<br />
    Replace \<YOUR\_USER> with the name of the Snowflake user to create.<br />
    Replace \<YOUR\_WAREHOUSE> with the name of the Snowflake warehouse the user runs queries on.<br />
    Replace \<YOUR\_DB> with the name of the database to create.<br />
    Replace \<YOUR\_SCHEMA> with the name of the schema to create.
  </Comments>
</Accordion>

## Register the Snowflake integration

1. Select **Integrations** in the left-hand navigation.
2. Click **Snowflake** in the **Add an Integration** section.
3. Enter a name for the integration.
4. Enter a description for the integration.
5. Enter your Snowflake credentials.
6. Click **Add**.

The integration panel includes a query to run on Snowflake to establish the security integration.

## Download the tutorial content

Download the tutorial content to your workstation:

```bash theme={null}
outerbounds tutorials pull --url https://outerbounds-journeys-content.s3.us-west-2.amazonaws.com/main/journeys.tar.gz --destination-dir ~/learn
```

The Snowflake tutorial content is in `~/learn/snowflake`. If you prefer a different location, replace `~/learn` with a directory of your choice.

<Tip>
  This command downloads all tutorial content as a single bundle. If you've already worked through other tutorials, you likely already have this and do not need to run the command again.
</Tip>

## Validate your setup

Open the notebook in `00-nb` from the `~/learn/snowflake` directory. Before running it, update the `integration`, `schema`, and `table_name` variables with your Snowflake integration name, schema, and table. This notebook validates that you can access Snowflake from an Anaconda Platform workstation.

## Query Snowflake from a notebook

The same notebook walks you through reading data from Snowflake after validation succeeds.

## Query Snowflake from a flow

Open the `01-flow` directory from the `~/learn/snowflake` directory. This directory contains a Metaflow flow that queries Snowflake. Before running it, update the `my_integration`, `my_schema`, and `my_table_name` variables in `flow.py` with the same values you used in the notebook.

Run the flow:

```bash theme={null}
cd ~/learn/snowflake/01-flow
python flow.py --environment=fast-bakery run --with kubernetes
```

## Next steps

To build on this tutorial:

* Query multiple tables and join data across schemas.
* Build automated reporting pipelines that read from Snowflake.
* Integrate Snowflake queries into your ML training workflows.
