SAP HANA Connector
The C3 Agentic AI Platform has a built-in connector for integrating with SAP HANA databases.
To connect to SAP HANA from your application:
- Add a SqlSourceSystem modeling the SAP HANA source system to your package.
- Configure the JdbcCredentials authorizing the connection to the external SAP HANA table.
- Add a SqlSourceCollection modeling the target SAP HANA table to your package.
- Create an External Type modeling the schema of the external SAP HANA table.
The following sections include detailed instructions for configuring the connection. For more information, see the SAP HANA Getting Started Guide and JDBC Connection Properties.
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 SAPSourceSystem.json to the \metadata\SqlSourceSystem directory of your package:
{
"name": "SAPSourceSystem"
}Configure the credential used to authorize the JDBC connection
Create a JdbcCredentials Type instance to configure the connection to the external SAP HANA database.
var credsRaw = {
"name": "< USER_DEFINED_NAME >",
"id": "< USER_DEFINED_ID >",
"url": "jdbc:sap://< SERVER_HOSTNAME >:443/?databaseName=< DATABASE_NAME >&encrypt=true&validateCertificate=false",
"username": "< DB_USERNAME >",
"password": "< DB_PASSWORD >",
"datastore": DatastoreType.HANA
}
creds = JdbcCredentials.make(credsRaw)
JdbcStore.forName("SAPSourceSystem").setCredentials(creds, ConfigOverride.APP);
JdbcStore.forName("SAPSourceSystem").setExternal(ConfigOverride.APP);Model the table containing the data
To model the external SAP HANA table in your application, create a SqlSourceCollection and set the following fields:
name— Identifier for the SAP HANA tablesource— Name of the External Type that models the schema of the external SAP HANA tablesourceSystem— Name of the SAP HANA SqlSourceSystem
For example, to model a table called DataTypesExample, you can add the following DataTypesExample.json to the \metadata\SqlSourceCollection directory of your package:
{
"name": "DataTypesExample",
"source": "DataTypesExample",
"sourceSystem":
{
"type": "SqlSourceSystem",
"name": "SAPSourceSystem"
}
}Model the table schema
To model the schema of the SAP HANA table in your application, create an External Entity Type with a schema name that case-sensitively matches the name of the table in the SAP HANA table.
Start by adding the following DataTypesExample.c3typ file to the \src directory of your package:
entity type DataTypesExample mixes External, NoSystemCols schema name 'DBADMIN.DATA_TYPES_EXAMPLE'For the DataTypesExample table, the schema name is a qualified name consisting of the database user 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("DataTypesExample").inferSourceType().declaredFieldTypes;
var myObject = {};
for (let i = 0; i < schema.length; i++) {
schemaName = schema[i].schemaName;
myObject[schemaName] = schema[i].valueType.name;
}
SAP HANA data types are mapped to C3 AI data types according to the following table:
| SAP HANA Data Types | C3 AI Data Types |
|---|---|
| DATE, TIME, SECONDDATE, TIMESTAMP | datetime, string, datetime, datetime |
| TINYINT, SMALLINT, INTEGER, BIGINT, SMALLDECIMAL, DECIMAL, REAL, DOUBLE | int32, int32, int32, int, decimal, decimal, float, double |
| BOOLEAN | boolean |
| VARCHAR, NVARCHAR, ALPHANUM, SHORTTEXT | string |
| VARBINARY | binary |
| BLOB, CLOB, NCLOB, TEXT | binary, string, string, string |
| REAL_VECTOR | string |
| ST_GEOMETRY, ST_POINT | string |
You can also access the source data types to validate the type inference:
SqlSourceCollection.forName("DataTypesExample").connect().columns;
Complete the External Entity Type definition:
entity type DataTypesExample mixes External, NoSystemCols schema name 'DBADMIN.DATA_TYPES_EXAMPLE' {
id: ~ schema name "VARCHAR_COL"
bigIntCol: int schema name "BIGINT_COL"
binaryCol: binary schema name "BINARY_COL"
blobCol: binary schema name "BLOB_COL"
booleanCol: boolean schema name "BOOLEAN_COL"
charCol: string schema name "CHAR_COL"
dateCol: datetime schema name "DATE_COL"
decimalCol: decimal schema name "DECIMAL_COL"
doubleCol: double schema name "DOUBLE_COL"
integerCol: int32 schema name "INTEGER_COL"
nCharCol: string schema name "NCHAR_COL"
nClobCol: string schema name "NCLOB_COL"
nVarCharCol: string schema name "NVARCHAR_COL"
realCol: float schema name "REAL_COL"
realVectorCol: string schema name "REAL_VECTOR_COL"
secondDateCol: datetime schema name "SECOND_DATE_COL"
smallDecimalCol: decimal schema name "SMALLDECIMAL_COL"
smallIntCol: int32 schema name "SMALLINT_COL"
timestampCol: datetime schema name "TIMESTAMP_COL"
tinyIntCol: int32 schema name "TINYINT_COL"
varBinaryCol: binary schema name "VARBINARY_COL"
varCharCol: string schema name "VARCHAR_COL"
}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 DataTypesExample Type, the VARCHAR_COL 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 SAP HANA table.
