Skip to content

Commit 3e04816

Browse files
zacdav-dbZac Davies
andauthored
Extending Unity Catalog Functions (Catalogs, Schemas, Volumes, Tables) (#80)
* Exporting UC table management endpoints. * Exporting list/get functions for catalogs/schemas. * Adding and exporting volume management functions. Minor tweaks to docs for UC functions to group into families. * fixing minor docs issues for R CMD CHECK --------- Co-authored-by: Zac Davies <[email protected]>
1 parent b07f0ab commit 3e04816

37 files changed

+1615
-259
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: brickster
22
Title: R Toolkit for 'Databricks'
3-
Version: 0.2.6
3+
Version: 0.2.7
44
Authors@R:
55
c(
66
person(given = "Zac",

NAMESPACE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ export(db_sql_warehouse_list)
110110
export(db_sql_warehouse_start)
111111
export(db_sql_warehouse_stop)
112112
export(db_token)
113+
export(db_uc_catalogs_get)
114+
export(db_uc_catalogs_list)
115+
export(db_uc_schemas_get)
116+
export(db_uc_schemas_list)
117+
export(db_uc_tables_delete)
118+
export(db_uc_tables_exists)
119+
export(db_uc_tables_get)
120+
export(db_uc_tables_list)
121+
export(db_uc_tables_summaries)
122+
export(db_uc_volumes_create)
123+
export(db_uc_volumes_delete)
124+
export(db_uc_volumes_get)
125+
export(db_uc_volumes_list)
126+
export(db_uc_volumes_update)
113127
export(db_volume_delete)
114128
export(db_volume_dir_create)
115129
export(db_volume_dir_delete)

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
# brickster 0.2.7
2+
3+
* Exporting UC table functions (`db_uc_table*`) (#72)
4+
* Adding support for `direct_download` option in `db_workspace_export()`
5+
* Exporting UC Catalog/Schema get/list functions (#72)
6+
* Adding support for UC Volume management (#72)
7+
18
# brickster 0.2.6
9+
210
* Fixing `db_volume_delete()` function (#73, @vladimirobucina)
311
* Adjustments to ensure {httr2} changes don't break things (#75, @hadley)
412

R/connection-pane.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ get_table_data <- function(catalog, schema, table, host, token, metadata = TRUE)
298298
catalog = catalog,
299299
schema = schema,
300300
table = table,
301+
omit_columns = FALSE,
302+
omit_properties = FALSE,
303+
omit_username = FALSE,
301304
host = host,
302305
token = token,
303306
)

R/dbfs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ db_dbfs_put <- function(path, file = NULL, contents = NULL, overwrite = FALSE,
429429

430430
body <- list(
431431
path = path,
432-
overwrite = ifelse(overwrite, "true", "false") # doesn't like bool :(
432+
overwrite = from_logical(overwrite)
433433
)
434434

435435
# file takes priority, so don't bother if file is also specified

R/request-helpers.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,9 @@ db_request_json <- function(req) {
123123
NULL
124124
}
125125
}
126+
127+
# some endpoints don't play nice and except strings 'true' and 'false'
128+
from_logical <- function(x) {
129+
stopifnot(is.logical(x))
130+
ifelse(x, "true", "false")
131+
}

R/uc-catalogs.R

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#' List Catalogs (Unity Catalog)
2+
#'
3+
#' @param max_results Maximum number of catalogs to return (default: 1000).
4+
#' @param include_browse Whether to include catalogs in the response for which
5+
#' the principal can only access selective metadata for.
6+
#' @inheritParams auth_params
7+
#' @inheritParams db_sql_query_history
8+
#' @inheritParams db_sql_warehouse_create
9+
#'
10+
#' @family Unity Catalog Management
11+
#'
12+
#' @returns List
13+
#' @export
14+
db_uc_catalogs_list <- function(max_results = 1000,
15+
include_browse = TRUE,
16+
page_token = NULL,
17+
host = db_host(), token = db_token(),
18+
perform_request = TRUE) {
19+
20+
stopifnot(max_results <= 1000)
21+
22+
body <- list(
23+
max_results = max_results,
24+
include_browse = include_browse,
25+
page_token = page_token
26+
)
27+
28+
req <- db_request(
29+
endpoint = "unity-catalog/catalogs",
30+
method = "GET",
31+
version = "2.1",
32+
host = host,
33+
token = token,
34+
body = body
35+
)
36+
37+
if (perform_request) {
38+
db_perform_request(req)$catalogs
39+
} else {
40+
req
41+
}
42+
}
43+
44+
45+
#' Get Catalog (Unity Catalog)
46+
#'
47+
#' @param catalog The name of the catalog.
48+
#' @inheritParams auth_params
49+
#' @inheritParams db_sql_query_history
50+
#' @inheritParams db_sql_warehouse_create
51+
#'
52+
#' @family Unity Catalog Management
53+
#'
54+
#' @returns List
55+
#' @export
56+
db_uc_catalogs_get <- function(catalog,
57+
host = db_host(), token = db_token(),
58+
perform_request = TRUE) {
59+
60+
req <- db_request(
61+
endpoint = "unity-catalog/catalogs/",
62+
method = "GET",
63+
version = "2.1",
64+
host = host,
65+
token = token
66+
) |>
67+
httr2::req_url_path_append(catalog)
68+
69+
if (perform_request) {
70+
db_perform_request(req)
71+
} else {
72+
req
73+
}
74+
}

R/uc-schemas.R

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#' List Schemas (Unity Catalog)
2+
#'
3+
#' @param catalog Parent catalog for schemas of interest.
4+
#' @param max_results Maximum number of schemas to return (default: 1000).
5+
#' @inheritParams auth_params
6+
#' @inheritParams db_sql_query_history
7+
#' @inheritParams db_sql_warehouse_create
8+
#'
9+
#' @family Unity Catalog Management
10+
#'
11+
#' @returns List
12+
#' @export
13+
db_uc_schemas_list <- function(catalog,
14+
max_results = 1000,
15+
page_token = NULL,
16+
host = db_host(), token = db_token(),
17+
perform_request = TRUE) {
18+
19+
stopifnot(max_results <= 1000)
20+
21+
body <- list(
22+
max_results = max_results,
23+
page_token = page_token
24+
)
25+
26+
req <- db_request(
27+
endpoint = "unity-catalog/schemas",
28+
method = "GET",
29+
version = "2.1",
30+
host = host,
31+
token = token,
32+
body = body
33+
) |>
34+
httr2::req_url_query(catalog_name = catalog)
35+
36+
if (perform_request) {
37+
db_perform_request(req)$schemas
38+
} else {
39+
req
40+
}
41+
}
42+
43+
44+
#' Get Schema (Unity Catalog)
45+
#'
46+
#' @param catalog Parent catalog for schema of interest.
47+
#' @param schema Schema of interest.
48+
#' @inheritParams auth_params
49+
#' @inheritParams db_sql_query_history
50+
#' @inheritParams db_uc_catalogs_list
51+
#'
52+
#' @family Unity Catalog Management
53+
#'
54+
#' @returns List
55+
#' @export
56+
db_uc_schemas_get <- function(catalog, schema,
57+
include_browse = TRUE,
58+
host = db_host(), token = db_token(),
59+
perform_request = TRUE) {
60+
61+
body <- list(
62+
include_browse = include_browse
63+
)
64+
65+
req <- db_request(
66+
endpoint = "unity-catalog/schemas/",
67+
method = "GET",
68+
version = "2.1",
69+
host = host,
70+
token = token,
71+
body = body
72+
) |>
73+
httr2::req_url_path_append(paste(catalog, schema, sep = "."))
74+
75+
if (perform_request) {
76+
db_perform_request(req)
77+
} else {
78+
req
79+
}
80+
}
81+

0 commit comments

Comments
 (0)