C3 AI Documentation Home

Snowflake Connector

The C3 Agentic AI Platform has a built-in connector for integrating with Snowflake databases.

To connect to Snowflake from your application:

  1. Add a SqlSourceSystem modeling the Snowflake source system to your package.
  2. Configure the JdbcCredentials authorizing the connection to the external Snowflake table.
  3. Add a SqlSourceCollection modeling the target Snowflake table to your package.
  4. Create an External Type modeling the schema of the external Snowflake table.

The following sections include detailed instructions for configuring the connection. For more information on configuring the JDBC driver, see Configuring the JDBC Driver in the Snowflake documentation.

Model the source system

Create a SqlSourceSystem and set the name field as the identifier for the external database system.

For example, you can add the following SnowflakeSourceSystem.json to the \metadata\SqlSourceSystem directory of your package:

JSON
{
    "name": "SnowflakeSourceSystem"
}

Configure Credentials for an External Snowflake SQL Source System

To connect to an external Snowflake database, you must configure credentials on a SqlSourceSystem.

Supported Credential Configuration Flow

  1. Create a JdbcCredentials instance using the Snowflake connection details.
  2. Attach the credentials to a SqlSourceSystem.
  3. Use the SqlSourceSystem as the entry point for schema discovery and data ingestion.

Required Credential Fields

When creating JdbcCredentials, provide the following fields:

  • serverEndpoint — Snowflake server hostname
  • port — Not required for Snowflake; use -1
  • datastoreTypeDatastoreType.SNOWFLAKE
  • database — Snowflake database name
  • schemaName — Schema within the database
  • username — Snowflake account username
  • password — Password for the account
  • warehouse — Snowflake warehouse name (provided as metadata)

Example: Configure Credentials on a SqlSourceSystem

JavaScript
// 1. Define the credentials using placeholders
var creds = JdbcCredentials.fromServerEndpoint(
  "your_account.snowflakecomputing.com", // Server endpoint to connect to
  -1,                                   // Port (not required for Snowflake)
  DatastoreType.SNOWFLAKE,
  "<DATABASE_NAME>",
  "<SCHEMA_NAME>",
  "<USERNAME>",
  "<PASSWORD>"
);

// 2. Add connection properties (for example, warehouse)
creds = creds.withField("properties", {
  "warehouse": "<WAREHOUSE_NAME>"
});

// 3. Register the credentials with the source system
SqlSourceSystem.forName("SnowflakeSourceSystem").setCredentials(creds);

With credentials attached, the `SqlSourceSystem` enables data preview, Source Collection configuration, and ingestion.

## Model the table containing the data

To model the external Snowflake table in your application, create a {@link SqlSourceCollection} and set the following fields:

`name`: Identifier for the Snowflake table
`source`: Name of the {@link External} Type that models the schema of the external Snowflake table
`sourceSystem`: Name of the Snowflake {@link SqlSourceSystem}

For example, to model a table called `RELIABILITY`, you can add the following `SnowflakeTable.json` to the
`\metadata\SqlSourceCollection` directory of your package:

```json
{
    "name" : "Reliability",
    "source" : "Reliability",
    "sourceSystem" : {
      "type" : "SqlSourceSystem",
      "name" : "SnowflakeSourceSystem"
    }
  }

Model the table schema

To model the schema of the Snowflake table in your application, create an External Entity Type with a schema name that case-sensitively matches the name of the table in the Snowflake table.

Start by adding the following Reliability.c3typ file to the \src directory of your package:

Type
entity type Reliability mixes External, NoSystemCols schema name 'PUBLIC.RELIABILITY'

For the RELIABILITY table, the schema name is a qualified name consisting of the schema name and table name separated by a dot. You can use the inferSourceType() method to access the table's C3 AI data types, which the platform infers from the source data types.

JavaScript
var schema = SqlSourceCollection.forName("Reliability").inferSourceType().declaredFieldTypes;

var myObject = {};
for (let i = 0; i < schema.length; i++) {
        schemaName = schema[i].schemaName;
        myObject[schemaName] = schema[i].valueType.name;
    }

myObject Snowflake

Snowflake data types are mapped to C3 AI data types according to the following table:

Snowflake Data TypesC3 AI Data Types
INT, INTEGER, SMALLINT, TINYINTint, int16, int32
BYTEINTbyte
BIGINTbigint
DECIMAL, NUMERIC, NUMBERdecimal
FLOAT, FLOAT4, FLOAT8float
DOUBLE, DOUBLE PRECISION, REALdouble
DATE, TIME, DATETIME, TIMESTAMP, TIMESTAMP_NTZ, TIMESTAMP_LTZ, TIMESTAMP_TZdatetime
BINARY, VARBINARYbinary
BOOLEANboolean
VARCHAR, CHAR, CHARACTER, STRING, TEXTstring
VARIANT, OBJECT, ARRAYjson
GEOGRAPHY, GEOMETRYNot Supported

You can also access the source data types to validate the type inference:

JavaScript
SqlSourceCollection.forName("Reliability").connect().columns;

Source Data Types

Complete the External Entity Type definition:

Type
entity type Reliability mixes External, NoSystemCols schema name "PUBLIC.RELIABILITY" {
    
    @db(dataTypeOverride='datetime')
    id: ~ schema name "TIMESTAMP"

    power: float schema name "ACTIVEPOWER_RESAMPLE_MEAN"

    rotationalSpeed: float schema name "GENERATORROTATIONSPEED_RESAMPLE_MEAN"

    gearOiltemp: float schema name "GEAROILTEMPERATURE_RESAMPLE_MEAN"

}

In the example Reliability Type, the TIMESTAMP column is used as the id field.

Read data from the table

After completing the External Entity Type definition, you can validate the configuration by fetching the External Type data from the Snowflake table:

JavaScript
c3Grid(Reliability.fetch());

Output

See also

Was this page helpful?