Search code examples
jdbcdatabricksazure-databricksdatabricks-sql

How to get the cluster's JDBC/ODBC parameters programmatically?


Databricks documentation shows how get the cluster's hostname, port, HTTP path, and JDBC URL parameters from the JDBC/ODBC tab in the UI. See image:

Databricks's JDBC/ODBC Tab
(source: databricks.com)

Is there a way to get the same information programmatically? I mean using the Databricks API or Databricks CLI. I am particularly interested in the HTTP path which contains the Workspace Id.


Solution

  • You can use the Get operation of the SQL Analytics REST API (maybe together with List) - it returns the JDBC connection string as a part of response (jdbc_url field):

    {
      "id": "123456790abcdef",
      "name": "My SQL endpoint",
      "cluster_size": "Medium",
      "min_num_clusters": 1,
      "max_num_clusters": 10,
      "auto_stop_mins": 30,
      "num_clusters": 5,
      "num_active_sessions": 30,
      "state": "RUNNING",
      "creator_name": "[email protected]",
      "jdbc_url":"jdbc:spark://<databricks-instance>:443/default;transportMode=http;ssl=1;AuthMech=3;httpPath=/sql/protocolv1/o/0123456790abcdef;",
      "odbc_params": {
        "host": "<databricks-instance>",
        "path": "/sql/protocolv1/o/0/123456790abcdef",
        "protocol": "https",
        "port": 443
      }
    }
    

    HTTP Path is also there, as path part of the odbc_params object.