zhengruifeng commented on code in PR #37133:
URL: https://github.com/apache/spark/pull/37133#discussion_r917227564
##########
R/pkg/R/catalog.R:
##########
@@ -403,21 +406,95 @@ listTables <- function(databaseName = NULL) {
dataFrame(callJMethod(jdst, "toDF"))
}
+#' Checks if the table with the specified name exists.
+#'
+#' Checks if the table with the specified name exists.
+#'
+#' @param tableName name of the table, allowed to be qualified with catalog
name
+#' @rdname tableExists
+#' @name tableExists
+#' @examples
+#' \dontrun{
+#' sparkR.session()
+#' databaseExists("spark_catalog.default.myTable")
+#' }
+#' @note since 3.4.0
+tableExists <- function(tableName) {
+ sparkSession <- getSparkSession()
+ if (class(tableName) != "character") {
+ stop("tableName must be a string.")
+ }
+ catalog <- callJMethod(sparkSession, "catalog")
+ callJMethod(catalog, "tableExists", tableName)
+}
+
+#' Get the table with the specified name
+#'
+#' Get the table with the specified name
+#'
+#' @param tableName the qualified or unqualified name that designates a table,
allowed to be
+#' qualified with catalog name
+#' @return A data.frame.
Review Comment:
```r
>
> schema <- structType(structField("name", "string"), structField("age",
"integer"), structField("height", "float"))
> createTable("people", source = "json", schema = schema)
SparkDataFrame[name:string, age:int, height:float]
> tbl <- getTable("people")
> tbl
name catalog namespace description tableType isTemporary
1 people spark_catalog default NULL MANAGED FALSE
>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]