# Snowflake

Connect RootCause.ai to your Snowflake data warehouse to import tables or run custom queries.

***

### Prerequisites

Before connecting, ensure you have:

* Snowflake account identifier (e.g., `org-account` or `account.region`)
* Username with access to the data you want to import
* Authentication credentials (password or RSA key pair)
* Warehouse, database, and schema names
* Network access from RootCause.ai to Snowflake

***

### Setting Up the Connection

1. Navigate to **Data** → **Datasets** in your workspace
2. Click **New Connection** and select **Snowflake**
3. Enter your connection details:

| Field              | Description            | Example           |
| ------------------ | ---------------------- | ----------------- |
| Account Identifier | Your Snowflake account | `myorg-myaccount` |
| Username           | Snowflake user         | `ANALYTICS_USER`  |
| Role (Optional)    | Role to assume         | `ANALYST_ROLE`    |

4. Choose an authentication method (see below)
5. Click **Test Connection** to verify your credentials
6. Click **Save** to create the connector

***

### Authentication Methods

**Password Authentication**

Enter your Snowflake password directly. This is the simplest method but may not be suitable for all security policies.

**Key Pair Authentication** (Recommended)

RSA key pair authentication is more secure and often required by enterprise security policies.

1. Select "Key Pair Authentication"
2. Click **Generate New Keys** – RootCause.ai will create an RSA key pair
3. Copy the **Public Key** displayed
4. Add the public key to your Snowflake user:

```sql
ALTER USER your_username SET RSA_PUBLIC_KEY='MIIBIjANBgkqh...';
```

The private key is securely stored by RootCause.ai and never exposed.

***

### Importing Data

Once your connector is saved, configure your import:

| Field     | Description            | Example        |
| --------- | ---------------------- | -------------- |
| Database  | Snowflake database     | `ANALYTICS_DB` |
| Schema    | Schema within database | `PUBLIC`       |
| Warehouse | Compute warehouse      | `COMPUTE_WH`   |

Then choose an import method:

**Import a Table**

Select "Table" and enter the table name. RootCause.ai will import all columns and rows.

**Custom SQL Query**

Select "Custom Query" to write your own SQL:

```sql
SELECT 
  customer_id,
  order_date,
  total_amount
FROM ORDERS
WHERE order_date >= '2024-01-01'
```

***

### What Happens When You Import

1. RootCause.ai connects to Snowflake using your credentials
2. The specified warehouse is used to execute the query
3. Results are streamed and stored in your workspace's data lake
4. Schema is automatically detected (column names, data types)
5. A preview is generated for verification

The imported dataset becomes available for use in [Data Views](https://docs.rootcause.ai/user-guide/data-management/data-views) and [Ontology](https://docs.rootcause.ai/core-technologies/ontology) mapping.

***

### Live Data Sync

You can configure automatic syncing to keep your dataset current:

* **Manual** – Only sync when you click "Sync Now"
* **Hourly** – Refresh every hour
* **Daily** – Refresh once per day
* **Weekly** – Refresh once per week

When a sync runs, the entire dataset is replaced with fresh data from Snowflake.

***

### Security Recommendations

* Use key pair authentication for production environments
* Create a dedicated user and role for RootCause.ai
* Grant only SELECT permissions on required objects
* Use a small warehouse size appropriate for your data volumes
* Consider using Snowflake's network policies if available

***

### Troubleshooting

**Connection failed**

* Verify the account identifier format (e.g., `org-account` not full URL)
* Check that the user exists and is not locked
* Ensure network connectivity to Snowflake

**Authentication error with key pair**

* Verify the public key was correctly added to the Snowflake user
* Ensure no extra whitespace in the key
* Check that the key hasn't been rotated or replaced

**Warehouse not found / suspended**

* Verify the warehouse name is correct
* Check that the user has USAGE permission on the warehouse
* Ensure the warehouse is not suspended (or has auto-resume enabled)

**Permission denied**

* Grant USAGE on the database and schema
* Grant SELECT on the required tables or views
* Verify the role has the necessary privileges
