Snowflake Connector
The C3 Agentic AI Platform has a built-in connector for integrating with Snowflake databases.
C3 AI Studio offers a low-code tool for building data pipelines called Data Fusion. Data Fusion configures data sources and connects them to C3 Canonicals and Entities. For more information, refer to the Snowflake connection walkthrough.
To connect to Snowflake from your application:
- Add a SqlSourceSystem modeling the Snowflake source system to your package.
- Configure the JdbcCredentials authorizing the connection to the external Snowflake table.
- Add a SqlSourceCollection modeling the target Snowflake table to your package.
- 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:
{
"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
- Create a
JdbcCredentialsinstance using the Snowflake connection details. - Attach the credentials to a
SqlSourceSystem. - Use the
SqlSourceSystemas 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 - datastoreType —
DatastoreType.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
// 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.
All Snowflake table and column names are uppercase.
Start by adding the following Reliability.c3typ file to the \src directory of your package:
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.
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;
}
Snowflake data types are mapped to C3 AI data types according to the following table:
| Snowflake Data Types | C3 AI Data Types |
|---|---|
| INT, INTEGER, SMALLINT, TINYINT | int, int16, int32 |
| BYTEINT | byte |
| BIGINT | bigint |
| DECIMAL, NUMERIC, NUMBER | decimal |
| FLOAT, FLOAT4, FLOAT8 | float |
| DOUBLE, DOUBLE PRECISION, REAL | double |
| DATE, TIME, DATETIME, TIMESTAMP, TIMESTAMP_NTZ, TIMESTAMP_LTZ, TIMESTAMP_TZ | datetime |
| BINARY, VARBINARY | binary |
| BOOLEAN | boolean |
| VARCHAR, CHAR, CHARACTER, STRING, TEXT | string |
| VARIANT, OBJECT, ARRAY | json |
| GEOGRAPHY, GEOMETRY | Not Supported |
You can also access the source data types to validate the type inference:
SqlSourceCollection.forName("Reliability").connect().columns;
Complete the External Entity Type definition:
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"
}The id field is required. If your table does not have a column called id, you can change the schema name for the corresponding ID field with the following annotation:
@db(dataTypeOverride="ID_FIELD_DATA_TYPE")
id: ~ schema name "ID_FIELD"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:
c3Grid(Reliability.fetch());