LangGraph HANA Checkpointer in a CAP Project
Thanks to David Diaz's LangGraph HANA Checkpointer, SAP HANA can be used as a checkpointer for thread persistence. This post covers one missing point I had when using it with CAP projects.
The schema
By default, when you provide a database connection, the checkpoint tables are created in the schema associated with your user:
conn = dbapi.connect(address="...", port=443, user="...", password="...")
checkpointer = HANASaver(conn=conn)
checkpointer.setup()
If you take the connection details from the binding - the user and password - the tables will be created outside the CAP project schema.
Taking the user from the HANA binding:
...
"hana": [
{
"label": "hana",
"name": "my-db",
"tags": [
"hana",
"database",
"relational"
],
...
"credentials": {
"database_id": "...",
"host": "....hanacloud.ondemand.com",
"port": "443",
"driver": "com.sap.db.jdbc.Driver",
"schema": "A66534E96NNNNNNNNNA245F35C6079C",
"user": "A66NNNNNNNNNNNNNNNNNNNNNNNN_NNNNNNNNNNNNNNNNNNNNSPN606_RT",
"password": "}(NZ~...."
...
The checkpointer tables will live in the A66NNNNNNNNNNNNNNNNNNNNNNNN_NNNNNNNNNNNNNNNNNNNNSPN606_RT
schema, which is outside the A66534E96NNNNNNNNNA245F35C6079C CAP project HDI container.
So when you connect via DB Explorer to the container using the quick path:
DB Explorer -> log in to Cloud Foundry -> add your container, you won't see the tables.
The goal
My requirement was to keep the tables inside the CAP project schema. However, the RT/DT users
from the binding do not have the CREATE privilege required to run the DDL statements used by the
checkpointer setup method.
Here's the approach I'm currently evaluating:
- Get the connection details from the binding. All details are extracted from the
VCAP_SERVICEShanaentry.
checkpointer = HANASaver.from_binding_with_db_deployer()
- Instead of calling the
setupmethod to execute the DDL, a dedicated.cdsfile has to be added underdb. It contains the required tables, which will be created by the HDI deployer:
This way, the tables are created under the CAP project schema.
Checkpointer code: https://github.com/wozjac/langgraph-checkpoint-hana/blob/main/langgraph_checkpoint_hana/saver.py