This documentation describes the integration of MindsDB with Snowflake, a cloud data warehouse used to store and analyze data. The integration allows MindsDB to access data stored in the Snowflake database and enhance it with AI capabilities.

Prerequisites

Before proceeding, ensure the following prerequisites are met:

  1. Install MindsDB locally via Docker or Docker Desktop.
  2. To connect Snowflake to MindsDB, install the required dependencies following this instruction.

Please note that, if you are using Docker to run MindsDB, before installing the dependencies for this integration as per the instructions given above, it is currently necessary to install Git in the container. To do this, run the following commands:

Start an interactive shell in the container:

docker exec -it mindsdb_container sh

If you haven’t specified a name when spinning up the MindsDB container with docker run, you can find it by running docker ps.

Install Git:

apt-get -y update
apt-get -y install git

The need to perform this step will be removed in future versions of MindsDB.

Connection

Establish a connection to your Snowflake database from MindsDB by executing the following SQL command:

CREATE DATABASE snowflake_datasource
WITH
    ENGINE = 'snowflake',
    PARAMETERS = {
        "account": "tvuibdy-vm85921",
        "user": "user",
        "password": "password",
        "database": "test_db"
    };

Required connection parameters include the following:

  • account: The Snowflake account identifier. This guide will help you find your account identifier.
  • user: The username for the Snowflake account.
  • password: The password for the Snowflake account.
  • database: The name of the Snowflake database to connect to.

Optional connection parameters include the following:

  • warehouse: The Snowflake warehouse to use for running queries.
  • schema: The database schema to use within the Snowflake database. Default is PUBLIC.
  • role: The Snowflake role to use.

Usage

Retrieve data from a specified table by providing the integration name, schema, and table name:

SELECT *
FROM snowflake_datasource.schema_name.table_name
LIMIT 10;

Run Snowflake SQL queries directly on the connected Snowflake database:

SELECT * FROM snowflake_datasource (

    --Native Query Goes Here
    SELECT
        employee_table.* EXCLUDE department_id,
        department_table.* RENAME department_name AS department
    FROM employee_table INNER JOIN department_table
        ON employee_table.department_id = department_table.department_id
    ORDER BY department, last_name, first_name;

);

The above examples utilize snowflake_datasource as the datasource name, which is defined in the CREATE DATABASE command.

Troubleshooting Guide

Database Connection Error

  • Symptoms: Failure to connect MindsDB with the Snowflake account.
  • Checklist:
    1. Make sure the Snowflake is active.
    2. Confirm that account, user, password and database are correct. Try a direct Snowflake connection using a client like DBeaver.
    3. Ensure a stable network between MindsDB and Snowflake.

SQL statement cannot be parsed by mindsdb_sql

  • Symptoms: SQL queries failing or not recognizing table names containing spaces or special characters.
  • Checklist:
    1. Ensure table names with spaces or special characters are enclosed in backticks.
    2. Examples:
      • Incorrect: SELECT * FROM integration.travel data
      • Incorrect: SELECT * FROM integration.‘travel data’
      • Correct: SELECT * FROM integration.`travel data`

This troubleshooting guide provided by Snowflake might also be helpful.