Avoid connection errors with automatic reconnection
mainThe Databricks SQL Connector for Python may close idle connections, which can cause errors in SQLFrame when it attempts to use a closed connection.
To prevent this, instead of passing a Connection object (which is required for the activate function), pass the connection parameters directly to the DatabricksSession constructor. This allows SQLFrame to manage the connection and automatically reconnect when needed.
import os
from sqlframe.databricks import DatabricksSession
session = DatabricksSession(
server_hostname="dbc-xxxxxxxx-xxxx.cloud.databricks.com",
http_path="/sql/1.0/warehouses/xxxxxxxxxxxxxxxx",
access_token=os.environ["ACCESS_TOKEN"],
auth_type="access_token",
catalog="catalog",
schema="schema",
)