Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make tables() alias instead of deprecate, error handling in tableName…
…s(), test for recoverPartitions/refresh*
  • Loading branch information
felixcheung committed Apr 1, 2017
commit 3c6693035b023d7c9c9e2caa3014247c130eb037
18 changes: 8 additions & 10 deletions R/pkg/R/catalog.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ dropTempView <- function(viewName) {
#'
#' Returns a SparkDataFrame containing names of tables in the given database.
#'
#' @param databaseName name of the database
#' @param databaseName (optional) name of the database
#' @return a SparkDataFrame
#' @rdname tables
#' @export
Expand All @@ -217,10 +217,8 @@ dropTempView <- function(viewName) {
#' @method tables default
#' @note tables since 1.4.0
tables.default <- function(databaseName = NULL) {
.Deprecated("listTables", old = "tables")
sparkSession <- getSparkSession()
jdf <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getTables", sparkSession, databaseName)
dataFrame(jdf)
# rename column to match previous output schema
withColumnRenamed(listTables(databaseName), "name", "tableName")
}

tables <- function(x, ...) {
Expand All @@ -231,7 +229,7 @@ tables <- function(x, ...) {
#'
#' Returns the names of tables in the given database as an array.
#'
#' @param databaseName name of the database
#' @param databaseName (optional) name of the database
#' @return a list of table names
#' @rdname tableNames
#' @export
Expand All @@ -245,10 +243,10 @@ tables <- function(x, ...) {
#' @note tableNames since 1.4.0
tableNames.default <- function(databaseName = NULL) {
sparkSession <- getSparkSession()
callJStatic("org.apache.spark.sql.api.r.SQLUtils",
"getTableNames",
sparkSession,
databaseName)
handledCallJMethod("org.apache.spark.sql.api.r.SQLUtils",
"getTableNames",
sparkSession,
databaseName)
}

tableNames <- function(x, ...) {
Expand Down
15 changes: 11 additions & 4 deletions R/pkg/inst/tests/testthat/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,12 @@ test_that("test tableNames and tables", {
df <- read.json(jsonPath)
createOrReplaceTempView(df, "table1")
expect_equal(length(tableNames()), 1)
expect_equal(length(tableNames("default")), 1)
tables <- listTables()
Copy link
Contributor

Choose a reason for hiding this comment

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

is tables() deprecated now ?

Copy link
Member Author

@felixcheung felixcheung Apr 1, 2017

Choose a reason for hiding this comment

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

right, there are some differences of the output (most notability catalog.listTables returns a Dataset<Table> - but I'm converting that into a DataFrame anyway), and I thought list* would be more consistent with other methods like listColumn(), listDatabases()

> head(tables("default"))
  database tableName isTemporary
1  default      json       FALSE
Warning message:
'tables' is deprecated.
Use 'listTables' instead.
See help("Deprecated")
> head(listTables("default"))
  name database description tableType isTemporary
1 json  default        <NA>  EXTERNAL       FALSE

If you think it makes sense, we could make tables an alias of listTables - it's going to call slightly different code on the Scala side and there are new columns and one different column name being returned.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed.

expect_equal(count(tables), 1)
expect_equal(count(suppressWarnings(tables())), count(tables))
expect_equal(count(tables()), count(tables))
expect_true("tableName" %in% colnames(tables()))
expect_true(all(c("tableName", "database", "isTemporary") %in% colnames(tables())))

suppressWarnings(registerTempTable(df, "table2"))
tables <- listTables()
Expand Down Expand Up @@ -2993,7 +2996,7 @@ test_that("catalog APIs, currentDatabase, setCurrentDatabase, listDatabases", {

test_that("catalog APIs, listTables, listColumns, listFunctions", {
tb <- listTables()
count <- count(suppressWarnings(tables()))
count <- count(tables())
expect_equal(nrow(tb), count)
expect_equal(colnames(tb), c("name", "database", "description", "tableType", "isTemporary"))

Expand All @@ -3014,8 +3017,6 @@ test_that("catalog APIs, listTables, listColumns, listFunctions", {
expect_error(listColumns("foo", "default"),
"Error in listColumns : analysis error - Table 'foo' does not exist in database 'default'")

dropTempView("cars")

f <- listFunctions()
expect_true(nrow(f) >= 200) # 250
expect_equal(colnames(f),
Expand All @@ -3024,6 +3025,12 @@ test_that("catalog APIs, listTables, listColumns, listFunctions", {
"org.apache.spark.sql.catalyst.expressions.Abs")
expect_error(listFunctions("foo_db"),
"Error in listFunctions : analysis error - Database 'foo_db' does not exist")

expect_error(recoverPartitions("cars"), NA)
expect_error(refreshTable("cars"), NA)
expect_error(refreshByPath("/"), NA)

dropTempView("cars")
})
Copy link
Contributor

Choose a reason for hiding this comment

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

We dont have tests for recoverPartitions refreshByPath and refreshTable ?

Copy link
Member Author

Choose a reason for hiding this comment

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

sharp eyes :) I was planning to add tests.

I tested these manually, but the steps are more involved and these are only thin wrappers in R I think we should defer to scala tests.


compare_list <- function(list1, list2) {
Expand Down