Github user felixcheung commented on a diff in the pull request:
https://github.com/apache/spark/pull/17483#discussion_r109291089
--- Diff: R/pkg/inst/tests/testthat/test_sparkSQL.R ---
@@ -2977,6 +2981,51 @@ 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, currentDatabase, setCurrentDatabase,
listDatabases", {
+ expect_equal(currentDatabase(), "default")
+ expect_error(setCurrentDatabase("default"), NA)
+ expect_error(setCurrentDatabase("foo"),
+ "Error in setCurrentDatabase : analysis error - Database
'foo' does not exist")
+ dbs <- collect(listDatabases())
+ expect_equal(names(dbs), c("name", "description", "locationUri"))
+ expect_equal(dbs[[1]], "default")
+})
+
+test_that("catalog APIs, listTables, listColumns, listFunctions", {
+ tb <- listTables()
+ count <- count(suppressWarnings(tables()))
+ expect_equal(nrow(tb), count)
+ expect_equal(colnames(tb), c("name", "database", "description",
"tableType", "isTemporary"))
+
+ createOrReplaceTempView(as.DataFrame(cars), "cars")
+
+ tb <- listTables()
+ expect_equal(nrow(tb), count + 1)
+ tbs <- collect(tb)
+ expect_true(nrow(tbs[tbs$name == "cars", ]) > 0)
+ expect_error(listTables("bar"),
+ "Error in listTables : no such database - Database 'bar'
not found")
+
+ c <- listColumns("cars")
+ expect_equal(nrow(c), 2)
+ expect_equal(colnames(c),
+ c("name", "description", "dataType", "nullable",
"isPartition", "isBucket"))
+ expect_equal(collect(c)[[1]][[1]], "speed")
+ 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),
+ c("name", "database", "description", "className",
"isTemporary"))
+ expect_equal(take(orderBy(f, "className"), 1)$className,
+ "org.apache.spark.sql.catalyst.expressions.Abs")
+ expect_error(listFunctions("foo_db"),
+ "Error in listFunctions : analysis error - Database
'foo_db' does not exist")
+})
--- End diff --
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.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]