Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/pkg/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,11 @@ export("as.DataFrame",
"createDataFrame",
"createExternalTable",
"createTable",
"currentCatalog",
"currentDatabase",
"dropTempTable",
"dropTempView",
"listCatalogs",
"listColumns",
"listDatabases",
"listFunctions",
Expand All @@ -493,6 +495,7 @@ export("as.DataFrame",
"refreshByPath",
"refreshTable",
"setCheckpointDir",
"setCurrentCatalog",
"setCurrentDatabase",
"spark.lapply",
"spark.addFile",
Expand Down
60 changes: 60 additions & 0 deletions R/pkg/R/catalog.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,66 @@

# catalog.R: SparkSession catalog functions

#' Returns the current default catalog
#'
#' Returns the current default catalog.
#'
#' @return name of the current default catalog.
#' @rdname currentCatalog
#' @name currentCatalog
#' @examples
#' \dontrun{
#' sparkR.session()
#' currentCatalog()
#' }
#' @note since 3.4.0
currentCatalog <- function() {
sparkSession <- getSparkSession()
catalog <- callJMethod(sparkSession, "catalog")
callJMethod(catalog, "currentCatalog")
}

#' Sets the current default catalog
#'
#' Sets the current default catalog.
#'
#' @param catalogName name of the catalog
#' @rdname setCurrentCatalog
#' @name setCurrentCatalog
#' @examples
#' \dontrun{
#' sparkR.session()
#' setCurrentCatalog("spark_catalog")
#' }
#' @note since 3.4.0
setCurrentCatalog <- function(catalogName) {
sparkSession <- getSparkSession()
if (class(catalogName) != "character") {
stop("catalogName must be a string.")
}
catalog <- callJMethod(sparkSession, "catalog")
invisible(handledCallJMethod(catalog, "setCurrentCatalog", catalogName))
}

#' Returns a list of catalog available
#'
#' Returns a list of catalog available.
#'
#' @return a SparkDataFrame of the list of catalog.
#' @rdname listCatalogs
#' @name listCatalogs
#' @examples
#' \dontrun{
#' sparkR.session()
#' listCatalogs()
#' }
#' @note since 3.4.0
listCatalogs <- function() {
sparkSession <- getSparkSession()
catalog <- callJMethod(sparkSession, "catalog")
dataFrame(callJMethod(callJMethod(catalog, "listCatalogs"), "toDF"))
}

#' (Deprecated) Create an external table
#'
#' Creates an external table based on the dataset in a data source,
Expand Down
5 changes: 4 additions & 1 deletion R/pkg/pkgdown/_pkgdown_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,20 @@ reference:

- title: "SQL Catalog"
- contents:
- currentCatalog
- currentDatabase
- dropTempTable
- dropTempView
- listCatalogs
- listColumns
- listDatabases
- listFunctions
- listTables
- refreshByPath
- refreshTable
- recoverPartitions
- setCurrentCatalog
- setCurrentDatabase
- tableNames
- tables
- uncacheTable
Expand All @@ -283,7 +287,6 @@ reference:
- getLocalProperty
- install.spark
- setCheckpointDir
- setCurrentDatabase
- setJobDescription
- setJobGroup
- setLocalProperty
Expand Down
11 changes: 11 additions & 0 deletions R/pkg/tests/fulltests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -4011,6 +4011,17 @@ test_that("Collect on DataFrame when NAs exists at the top of a timestamp column
expect_equal(class(ldf3$col3), c("POSIXct", "POSIXt"))
})

test_that("catalog APIs, listCatalogs, setCurrentCatalog, currentCatalog", {
expect_equal(currentCatalog(), "spark_catalog")
expect_error(setCurrentCatalog("spark_catalog"), NA)
expect_error(setCurrentCatalog("zxwtyswklpf"),
paste0("Error in setCurrentCatalog : ",
"org.apache.spark.sql.connector.catalog.CatalogNotFoundException: ",
"Catalog 'zxwtyswklpf' plugin class not found: ",
"spark.sql.catalog.zxwtyswklpf is not defined"))
catalogs <- collect(listCatalogs())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catalogs is empty here, see #36904 (comment)

})

test_that("catalog APIs, currentDatabase, setCurrentDatabase, listDatabases", {
expect_equal(currentDatabase(), "default")
expect_error(setCurrentDatabase("default"), NA)
Expand Down