Snowflake Connector
The C3 Agentic AI Platform has a built-in connector for integrating with Snowflake databases.
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 the credential used to authorize the JDBC connection
Create a JdbcCredentials Type instance to configure the connection to the external Snowflake table by passing the following fields to the JdbcCredentials.fromServerEndpoint() method:
serverEndpoint— Snowflake server hostnameport— Not required for Snowflake; use -1datastoreType— Specifies that the JdbcCredentials authorizes a connection to Snowflakedatabase— The name of the Snowflake database that you are connecting toschemaName— The name of the schema within the databaseusername— The account with authorization to access the Snowflake database tablepassword— The password for this accountwarehouse— additional metadata required to make the JDBC connection
For example, run the following from console to configure the JdbcCredentials:
var creds = JdbcCredentials.fromServerEndpoint("my_sf_instance.snowflakecomputing.com",
-1,
DatastoreType.SNOWFLAKE,
"SOME_DB",
"SOME_SCHEMA",
"some_account",
"some_password");
creds = creds.withField("properties", {"warehouse" : "SOME_WH"});
JdbcStore.forName("SnowflakeSourceSystem").setCredentials(creds, ConfigOverride.APP);
JdbcStore.forName("SnowflakeSourceSystem").setExternal(ConfigOverride.APP);Model the table containing the data
To model the external Snowflake table in your application, create a SqlSourceCollection and set the following fields:
name: Identifier for the Snowflake table source: Name of the External Type that models the schema of the external Snowflake table sourceSystem: Name of the Snowflake SqlSourceSystem
For example, to model a table called RELIABILITY, you can add the following SnowflakeTable.json to the \metadata\SqlSourceCollection directory of your package:
{
"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());