SAP HANA Connector
The C3 Agentic AI Platform has a built-in Java Database Connectivity (JDBC) 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 database.
- 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.
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, 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 >",
"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)
SqlSourceSystem.forName("SAPSourceSystem").setCredentials(creds);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, 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. Give the entity Type a schema name that matches the name of the SAP HANA table exactly. The schema name is case sensitive.
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: the database user and the table name, separated by a dot. Use the inferSourceType() method to see the C3 AI data types that the platform infers from the source data types of the table:
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;
}
The platform maps SAP HANA data types 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 |
To validate the type inference, view the source data types:
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 has no column called id, change the schema name for the corresponding id field with the following annotation:
@db(dataTypeOverride="ID_FIELD_DATA_TYPE")
id: ~ schema name "ID_FIELD"The example DataTypesExample Type uses the VARCHAR_COL column as the id field.
Read data from the table
After you complete the External entity Type definition, validate the configuration. Call DataTypesExample.fetch() to fetch the External Type data from the SAP HANA table.
