|
17 | 17 |
|
18 | 18 | # catalog.R: SparkSession catalog functions |
19 | 19 |
|
20 | | -#' Create an external table |
| 20 | +#' (Deprecated) Create an external table |
21 | 21 | #' |
22 | 22 | #' Creates an external table based on the dataset in a data source, |
23 | 23 | #' Returns a SparkDataFrame associated with the external table. |
|
29 | 29 | #' @param tableName a name of the table. |
30 | 30 | #' @param path the path of files to load. |
31 | 31 | #' @param source the name of external data source. |
32 | | -#' @param schema the schema of the data for certain data source. |
| 32 | +#' @param schema the schema of the data required for some data sources. |
33 | 33 | #' @param ... additional argument(s) passed to the method. |
34 | 34 | #' @return A SparkDataFrame. |
35 | | -#' @rdname createExternalTable |
| 35 | +#' @rdname createExternalTable-deprecated |
| 36 | +#' @seealso \link{createTable} |
36 | 37 | #' @export |
37 | 38 | #' @examples |
38 | 39 | #'\dontrun{ |
|
43 | 44 | #' @method createExternalTable default |
44 | 45 | #' @note createExternalTable since 1.4.0 |
45 | 46 | createExternalTable.default <- function(tableName, path = NULL, source = NULL, schema = NULL, ...) { |
| 47 | + .Deprecated("createTable", old = "createExternalTable") |
| 48 | + createTable(tableName, path, source, schema, ...) |
| 49 | +} |
| 50 | + |
| 51 | +createExternalTable <- function(x, ...) { |
| 52 | + dispatchFunc("createExternalTable(tableName, path = NULL, source = NULL, ...)", x, ...) |
| 53 | +} |
| 54 | + |
| 55 | +#' Creates a table based on the dataset in a data source |
| 56 | +#' |
| 57 | +#' Creates a table based on the dataset in a data source. Returns a SparkDataFrame associated with |
| 58 | +#' the table. |
| 59 | +#' |
| 60 | +#' The data source is specified by the \code{source} and a set of options(...). |
| 61 | +#' If \code{source} is not specified, the default data source configured by |
| 62 | +#' "spark.sql.sources.default" will be used. When a \code{path} is specified, an external table is |
| 63 | +#' created from the data at the given path. Otherwise a managed table is created. |
| 64 | +#' |
| 65 | +#' @param tableName the qualified or unqualified name that designates a table. If no database |
| 66 | +#' identifier is provided, it refers to a table in the current database. |
| 67 | +#' @param path (optional) the path of files to load. |
| 68 | +#' @param source (optional) the name of the data source. |
| 69 | +#' @param schema (optional) the schema of the data required for some data sources. |
| 70 | +#' @param ... additional named parameters as options for the data source. |
| 71 | +#' @return A SparkDataFrame. |
| 72 | +#' @rdname createTable |
| 73 | +#' @seealso \link{createExternalTable} |
| 74 | +#' @export |
| 75 | +#' @examples |
| 76 | +#'\dontrun{ |
| 77 | +#' sparkR.session() |
| 78 | +#' df <- createTable("myjson", path="path/to/json", source="json", schema) |
| 79 | +#' |
| 80 | +#' createTable("people", source = "json", schema = schema) |
| 81 | +#' insertInto(df, "people") |
| 82 | +#' } |
| 83 | +#' @name createTable |
| 84 | +#' @note createTable since 2.2.0 |
| 85 | +createTable <- function(tableName, path = NULL, source = NULL, schema = NULL, ...) { |
46 | 86 | sparkSession <- getSparkSession() |
47 | 87 | options <- varargsToStrEnv(...) |
48 | 88 | if (!is.null(path)) { |
49 | 89 | options[["path"]] <- path |
50 | 90 | } |
| 91 | + if (is.null(source)) { |
| 92 | + source <- getDefaultSqlSource() |
| 93 | + } |
51 | 94 | catalog <- callJMethod(sparkSession, "catalog") |
52 | 95 | if (is.null(schema)) { |
53 | | - sdf <- callJMethod(catalog, "createExternalTable", tableName, source, options) |
| 96 | + sdf <- callJMethod(catalog, "createTable", tableName, source, options) |
| 97 | + } else if (class(schema) == "structType") { |
| 98 | + sdf <- callJMethod(catalog, "createTable", tableName, source, schema$jobj, options) |
54 | 99 | } else { |
55 | | - sdf <- callJMethod(catalog, "createExternalTable", tableName, source, schema$jobj, options) |
| 100 | + stop("schema must be a structType.") |
56 | 101 | } |
57 | 102 | dataFrame(sdf) |
58 | 103 | } |
59 | 104 |
|
60 | | -createExternalTable <- function(x, ...) { |
61 | | - dispatchFunc("createExternalTable(tableName, path = NULL, source = NULL, ...)", x, ...) |
62 | | -} |
63 | | - |
64 | 105 | #' Cache Table |
65 | 106 | #' |
66 | 107 | #' Caches the specified table in-memory. |
|
0 commit comments