Skip to content

Commit feb334c

Browse files
authored
Feature/Unity Catalog API (#10)
* Unity Catalog Boiler Plate * Unity Catalog Impl * PR Template Update on Versions * Doxyfile update * v0.2.3
1 parent 4ec21f6 commit feb334c

File tree

14 files changed

+1181
-14
lines changed

14 files changed

+1181
-14
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
- [ ] Code builds successfully
1919
- [ ] Tests pass
2020
- [ ] Documentation updated (if needed)
21-
21+
- [ ] Update version and tag

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.14)
22
project(databricks_sdk
3-
VERSION 0.2.2
3+
VERSION 0.2.3
44
DESCRIPTION "Databricks C++ SDK"
55
LANGUAGES CXX)
66

@@ -97,6 +97,8 @@ set(SOURCES
9797
src/compute/compute_types.cpp
9898
src/compute/compute.cpp
9999
src/connection_pool.cpp
100+
src/unity_catalog/unity_catalog_types.cpp
101+
src/unity_catalog/unity_catalog.cpp
100102
src/internal/pool_manager.cpp
101103
src/internal/logger.cpp
102104
src/internal/http_client.cpp
@@ -110,6 +112,8 @@ set(HEADERS
110112
include/databricks/jobs/jobs.h
111113
include/databricks/compute/compute.h
112114
include/databricks/compute/compute_types.h
115+
include/databricks/unity_catalog/unity_catalog.h
116+
include/databricks/unity_catalog/unity_catalog_types.h
113117
)
114118

115119
# Internal headers (not installed)

Doxyfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
# Project information
44
PROJECT_NAME = "Databricks C++ SDK"
5-
PROJECT_NUMBER = "0.2.2"
5+
PROJECT_NUMBER = "0.2.3"
66
PROJECT_BRIEF = "Interact with Databricks via an SDK"
77
OUTPUT_DIRECTORY = docs
88

99
# Input configuration
10-
INPUT = include/databricks src README.md
11-
FILE_PATTERNS = *.h *.cpp *.md
10+
INPUT = include/databricks README.md
11+
FILE_PATTERNS = *.h *.md
1212
RECURSIVE = YES
13-
EXCLUDE = src/internal
14-
EXCLUDE_PATTERNS = */build/* */cmake/*
13+
EXCLUDE =
14+
EXCLUDE_PATTERNS = */build/* */cmake/* */internal/*
1515

1616
# Output formats
1717
GENERATE_HTML = YES

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A C++ SDK for Databricks, providing an interface for interacting with Databricks services.
88

9-
**Latest Release**: [v0.2.2](https://github.com/calvinjmin/databricks-sdk-cpp/releases/tag/v0.2.2)
9+
**Latest Release**: [v0.2.3](https://github.com/calvinjmin/databricks-sdk-cpp/releases/tag/v0.2.3)
1010

1111
**Author**: Calvin Min ([email protected])
1212

examples/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ target_link_libraries(jobs_example PRIVATE databricks_sdk)
1212
add_executable(compute_example compute_example.cpp)
1313
target_link_libraries(compute_example PRIVATE databricks_sdk)
1414

15+
# ========== Unity Catalog API Examples ==========
16+
add_executable(unity_catalog_example unity_catalog_example.cpp)
17+
target_link_libraries(unity_catalog_example PRIVATE databricks_sdk)
18+
1519
# Set RPATH for all examples to find ODBC libraries
1620
set_target_properties(
1721
simple_query
1822
jobs_example
1923
compute_example
24+
unity_catalog_example
2025
PROPERTIES
2126
BUILD_RPATH "${CMAKE_BINARY_DIR};/opt/homebrew/lib;/usr/local/lib"
2227
INSTALL_RPATH "/opt/homebrew/lib;/usr/local/lib"

examples/unity_catalog_example.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @file unity_catalog_example.cpp
3+
* @brief Example demonstrating the Databricks Unity Catalog API
4+
*
5+
* This example shows how to:
6+
* 1. List all catalogs in your metastore
7+
* 2. Get details for a specific catalog
8+
* 3. List schemas in a catalog
9+
* 4. List tables in a schema
10+
*/
11+
12+
#include "databricks/unity_catalog/unity_catalog.h"
13+
#include "databricks/core/config.h"
14+
#include <iostream>
15+
#include <exception>
16+
17+
int main() {
18+
try {
19+
// Load configuration from environment
20+
databricks::AuthConfig auth = databricks::AuthConfig::from_environment();
21+
22+
std::cout << "Connecting to: " << auth.host << std::endl;
23+
std::cout << "======================================\n" << std::endl;
24+
25+
// Create Unity Catalog API client (uses API version 2.1 by default)
26+
databricks::UnityCatalog uc(auth);
27+
28+
// ===================================================================
29+
// Example 1: List all catalogs
30+
// ===================================================================
31+
std::cout << "1. Listing all catalogs:" << std::endl;
32+
std::cout << "------------------------" << std::endl;
33+
34+
auto catalogs = uc.list_catalogs();
35+
std::cout << "Found " << catalogs.size() << " catalogs:\n" << std::endl;
36+
37+
for ( int i = 0; i < std::min(static_cast<int>(catalogs.size()), 10); i++ ) {
38+
const auto& catalog = catalogs[i];
39+
std::cout << " Catalog: " << catalog.name << std::endl;
40+
std::cout << " Owner: " << catalog.owner << std::endl;
41+
std::cout << " Type: " << catalog.catalog_type << std::endl;
42+
std::cout << " Metastore: " << catalog.metastore_id << std::endl;
43+
if (!catalog.comment.empty()) {
44+
std::cout << " Comment: " << catalog.comment << std::endl;
45+
}
46+
std::cout << std::endl;
47+
}
48+
49+
// ===================================================================
50+
// Example 2: Get details for a specific catalog
51+
// ===================================================================
52+
if (!catalogs.empty()) {
53+
std::string catalog_name = catalogs[0].name;
54+
55+
std::cout << "\n2. Getting details for catalog '" << catalog_name << "':" << std::endl;
56+
std::cout << "-----------------------------------------------------" << std::endl;
57+
58+
auto catalog_details = uc.get_catalog(catalog_name);
59+
std::cout << " Name: " << catalog_details.name << std::endl;
60+
std::cout << " Full Name: " << catalog_details.full_name << std::endl;
61+
std::cout << " Owner: " << catalog_details.owner << std::endl;
62+
std::cout << " Type: " << catalog_details.catalog_type << std::endl;
63+
std::cout << " Created At: " << catalog_details.created_at << std::endl;
64+
std::cout << " Updated At: " << catalog_details.updated_at << std::endl;
65+
66+
if (!catalog_details.properties.empty()) {
67+
std::cout << " Properties:" << std::endl;
68+
for (const auto& [key, value] : catalog_details.properties) {
69+
std::cout << " " << key << ": " << value << std::endl;
70+
}
71+
}
72+
std::cout << std::endl;
73+
74+
// ===============================================================
75+
// Example 3: List schemas in the catalog
76+
// ===============================================================
77+
std::cout << "\n3. Listing schemas in catalog '" << catalog_name << "':" << std::endl;
78+
std::cout << "-----------------------------------------------------------" << std::endl;
79+
80+
auto schemas = uc.list_schemas(catalog_name);
81+
std::cout << "Found " << schemas.size() << " schemas:\n" << std::endl;
82+
83+
for (const auto& schema : schemas) {
84+
std::cout << " Schema: " << schema.name << std::endl;
85+
std::cout << " Full Name: " << schema.full_name << std::endl;
86+
std::cout << " Owner: " << schema.owner << std::endl;
87+
if (!schema.comment.empty()) {
88+
std::cout << " Comment: " << schema.comment << std::endl;
89+
}
90+
std::cout << std::endl;
91+
}
92+
93+
// ===============================================================
94+
// Example 4: List tables in the first schema
95+
// ===============================================================
96+
if (!schemas.empty()) {
97+
std::string schema_name = schemas[0].name;
98+
99+
std::cout << "\n4. Listing tables in '" << catalog_name << "." << schema_name << "':" << std::endl;
100+
std::cout << "----------------------------------------------------------------" << std::endl;
101+
102+
auto tables = uc.list_tables(catalog_name, schema_name);
103+
std::cout << "Found " << tables.size() << " tables:\n" << std::endl;
104+
105+
for (const auto& table : tables) {
106+
std::cout << " Table: " << table.name << std::endl;
107+
std::cout << " Full Name: " << table.full_name << std::endl;
108+
std::cout << " Type: " << table.table_type << std::endl;
109+
std::cout << " Format: " << table.data_source_format << std::endl;
110+
std::cout << " Owner: " << table.owner << std::endl;
111+
std::cout << " Columns: " << table.columns.size() << std::endl;
112+
if (!table.comment.empty()) {
113+
std::cout << " Comment: " << table.comment << std::endl;
114+
}
115+
std::cout << std::endl;
116+
}
117+
}
118+
}
119+
120+
std::cout << "\n======================================" << std::endl;
121+
std::cout << "Unity Catalog API example completed successfully!" << std::endl;
122+
123+
} catch (const std::exception& e) {
124+
std::cerr << "Error: " << e.what() << std::endl;
125+
return 1;
126+
}
127+
128+
return 0;
129+
}

0 commit comments

Comments
 (0)