Databricks C++ SDK 0.2.4
Interact with Databricks via an SDK
Loading...
Searching...
No Matches
unity_catalog.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <string>
7#include <vector>
8#include <memory>
9
10namespace databricks {
11 // Forward declaration for dependency injection
12 namespace internal {
13 class IHttpClient;
14 }
15
16 /**
17 * @brief Client for interacting with the Databricks Unity Catalog API
18 *
19 * Unity Catalog provides a unified governance solution for data and AI assets.
20 * This implementation uses Unity Catalog REST API 2.1.
21 *
22 * Example usage:
23 * @code
24 * databricks::AuthConfig auth = databricks::AuthConfig::from_environment();
25 * databricks::UnityCatalog uc(auth);
26 *
27 * // List all catalogs
28 * auto catalogs = uc.list_catalogs();
29 *
30 * // Get specific catalog details
31 * auto catalog = uc.get_catalog("main");
32 *
33 * // Create a new catalog
34 * databricks::CreateCatalogRequest req;
35 * req.name = "my_catalog";
36 * req.comment = "My data catalog";
37 * uc.create_catalog(req);
38 *
39 * // List schemas in a catalog
40 * auto schemas = uc.list_schemas("main");
41 *
42 * // List tables in a schema
43 * auto tables = uc.list_tables("main", "default");
44 * @endcode
45 */
47 public:
48 /**
49 * @brief Construct a Unity Catalog API client
50 * @param auth Authentication configuration with host and token
51 * @param api_version Unity Catalog API version to use (default: "2.1")
52 */
53 explicit UnityCatalog(const AuthConfig& auth, const std::string& api_version = "2.1");
54
55 /**
56 * @brief Construct a Unity Catalog API client with dependency injection (for testing)
57 * @param http_client Injected HTTP client (use MockHttpClient for unit tests)
58 * @note This constructor is primarily for testing with mock HTTP clients
59 */
60 explicit UnityCatalog(std::shared_ptr<internal::IHttpClient> http_client);
61
62 /**
63 * @brief Destructor
64 */
66
67 // Disable copy
68 UnityCatalog(const UnityCatalog&) = delete;
70
71 // ==================== CATALOG OPERATIONS ====================
72
73 /**
74 * @brief List all catalogs in the metastore
75 *
76 * @return Vector of CatalogInfo objects
77 * @throws std::runtime_error if the API request fails
78 */
79 std::vector<CatalogInfo> list_catalogs();
80
81 /**
82 * @brief Get detailed information about a specific catalog
83 *
84 * @param catalog_name The name of the catalog
85 * @return CatalogInfo object with full details
86 * @throws std::runtime_error if the catalog is not found or the API request fails
87 */
88 CatalogInfo get_catalog(const std::string& catalog_name);
89
90 /**
91 * @brief Create a new catalog
92 *
93 * @param request Configuration for the new catalog
94 * @return CatalogInfo object representing the created catalog
95 * @throws std::runtime_error if the API request fails
96 */
98
99 /**
100 * @brief Update an existing catalog
101 *
102 * @param request Configuration for updating the catalog
103 * @return CatalogInfo object representing the updated catalog
104 * @throws std::runtime_error if the API request fails
105 */
107
108 /**
109 * @brief Delete a catalog
110 *
111 * @param catalog_name The name of the catalog to delete
112 * @param force If true, deletes the catalog even if it's not empty
113 * @return true if the operation was successful
114 * @throws std::runtime_error if the API request fails
115 *
116 * @note By default, you cannot delete a catalog that contains schemas.
117 * Set force=true to delete a catalog and all its contents.
118 */
119 bool delete_catalog(const std::string& catalog_name, bool force = false);
120
121 // ==================== SCHEMA OPERATIONS ====================
122
123 /**
124 * @brief List all schemas in a catalog
125 *
126 * @param catalog_name The name of the catalog
127 * @return Vector of SchemaInfo objects
128 * @throws std::runtime_error if the API request fails
129 */
130 std::vector<SchemaInfo> list_schemas(const std::string& catalog_name);
131
132 /**
133 * @brief Get detailed information about a specific schema
134 *
135 * @param full_name The full name of the schema (catalog.schema)
136 * @return SchemaInfo object with full details
137 * @throws std::runtime_error if the schema is not found or the API request fails
138 */
139 SchemaInfo get_schema(const std::string& full_name);
140
141 /**
142 * @brief Create a new schema
143 *
144 * @param request Configuration for the new schema
145 * @return SchemaInfo object representing the created schema
146 * @throws std::runtime_error if the API request fails
147 */
149
150 /**
151 * @brief Update an existing schema
152 *
153 * @param request Configuration for updating the schema
154 * @return SchemaInfo object representing the updated schema
155 * @throws std::runtime_error if the API request fails
156 */
158
159 /**
160 * @brief Delete a schema
161 *
162 * @param full_name The full name of the schema to delete (catalog.schema)
163 * @return true if the operation was successful
164 * @throws std::runtime_error if the API request fails
165 *
166 * @note The schema must be empty (no tables) before deletion
167 */
168 bool delete_schema(const std::string& full_name);
169
170 // ==================== TABLE OPERATIONS ====================
171
172 /**
173 * @brief List all tables in a schema
174 *
175 * @param catalog_name The name of the catalog
176 * @param schema_name The name of the schema
177 * @return Vector of TableInfo objects
178 * @throws std::runtime_error if the API request fails
179 */
180 std::vector<TableInfo> list_tables(const std::string& catalog_name,
181 const std::string& schema_name);
182
183 /**
184 * @brief Get detailed information about a specific table
185 *
186 * @param full_name The full name of the table (catalog.schema.table)
187 * @return TableInfo object with full details
188 * @throws std::runtime_error if the table is not found or the API request fails
189 */
190 TableInfo get_table(const std::string& full_name);
191
192 /**
193 * @brief Delete a table
194 *
195 * @param full_name The full name of the table to delete (catalog.schema.table)
196 * @return true if the operation was successful
197 * @throws std::runtime_error if the API request fails
198 *
199 * @note For managed tables, this also deletes the underlying data.
200 * For external tables, only the metadata is deleted.
201 */
202 bool delete_table(const std::string& full_name);
203
204 private:
205 class Impl;
206 std::unique_ptr<Impl> pimpl_;
207
208 // Parsing methods
209 static CatalogInfo parse_catalog(const std::string& json_str);
210 static std::vector<CatalogInfo> parse_catalog_list(const std::string& json_str);
211 static SchemaInfo parse_schema(const std::string& json_str);
212 static std::vector<SchemaInfo> parse_schema_list(const std::string& json_str);
213 static TableInfo parse_table(const std::string& json_str);
214 static std::vector<TableInfo> parse_table_list(const std::string& json_str);
215 static ColumnInfo parse_column(const std::string& json_str);
216 };
217
218} // namespace databricks
Client for interacting with the Databricks Unity Catalog API.
UnityCatalog(const UnityCatalog &)=delete
SchemaInfo create_schema(const CreateSchemaRequest &request)
Create a new schema.
std::vector< SchemaInfo > list_schemas(const std::string &catalog_name)
List all schemas in a catalog.
std::vector< TableInfo > list_tables(const std::string &catalog_name, const std::string &schema_name)
List all tables in a schema.
CatalogInfo create_catalog(const CreateCatalogRequest &request)
Create a new catalog.
TableInfo get_table(const std::string &full_name)
Get detailed information about a specific table.
std::vector< CatalogInfo > list_catalogs()
List all catalogs in the metastore.
CatalogInfo get_catalog(const std::string &catalog_name)
Get detailed information about a specific catalog.
UnityCatalog(std::shared_ptr< internal::IHttpClient > http_client)
Construct a Unity Catalog API client with dependency injection (for testing)
CatalogInfo update_catalog(const UpdateCatalogRequest &request)
Update an existing catalog.
bool delete_catalog(const std::string &catalog_name, bool force=false)
Delete a catalog.
~UnityCatalog()
Destructor.
UnityCatalog(const AuthConfig &auth, const std::string &api_version="2.1")
Construct a Unity Catalog API client.
SchemaInfo update_schema(const UpdateSchemaRequest &request)
Update an existing schema.
bool delete_table(const std::string &full_name)
Delete a table.
UnityCatalog & operator=(const UnityCatalog &)=delete
bool delete_schema(const std::string &full_name)
Delete a schema.
SchemaInfo get_schema(const std::string &full_name)
Get detailed information about a specific schema.
Core authentication configuration shared across all Databricks features.
Definition config.h:16
Represents a Unity Catalog catalog.
Represents column information.
Configuration for creating a catalog.
Configuration for creating a schema.
Represents a Unity Catalog schema.
Represents a Unity Catalog table.
Configuration for updating a catalog.
Configuration for updating a schema.