diff options
author | Felix Cheung <felixcheung_m@hotmail.com> | 2016-06-20 13:46:24 -0700 |
---|---|---|
committer | Shivaram Venkataraman <shivaram@cs.berkeley.edu> | 2016-06-20 13:46:24 -0700 |
commit | 359c2e827d5682249c009e83379a5ee8e5aa4e89 (patch) | |
tree | 1aac6f407a2fac66b44bd4e03672f58d311ee759 | |
parent | b0f2fb5b9729b38744bf784f2072f5ee52314f87 (diff) | |
download | spark-359c2e827d5682249c009e83379a5ee8e5aa4e89.tar.gz spark-359c2e827d5682249c009e83379a5ee8e5aa4e89.tar.bz2 spark-359c2e827d5682249c009e83379a5ee8e5aa4e89.zip |
[SPARK-15159][SPARKR] SparkSession roxygen2 doc, programming guide, example updates
## What changes were proposed in this pull request?
roxygen2 doc, programming guide, example updates
## How was this patch tested?
manual checks
shivaram
Author: Felix Cheung <felixcheung_m@hotmail.com>
Closes #13751 from felixcheung/rsparksessiondoc.
-rw-r--r-- | R/pkg/R/DataFrame.R | 169 | ||||
-rw-r--r-- | R/pkg/R/SQLContext.R | 47 | ||||
-rw-r--r-- | R/pkg/R/mllib.R | 6 | ||||
-rw-r--r-- | R/pkg/R/schema.R | 24 | ||||
-rw-r--r-- | R/pkg/R/sparkR.R | 7 | ||||
-rw-r--r-- | docs/sparkr.md | 99 | ||||
-rw-r--r-- | examples/src/main/r/data-manipulation.R | 15 | ||||
-rw-r--r-- | examples/src/main/r/dataframe.R | 13 | ||||
-rw-r--r-- | examples/src/main/r/ml.R | 21 |
9 files changed, 162 insertions, 239 deletions
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index f3a3eff46d..583d3aefd4 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -35,12 +35,11 @@ setOldClass("structType") #' @slot env An R environment that stores bookkeeping states of the SparkDataFrame #' @slot sdf A Java object reference to the backing Scala DataFrame #' @seealso \link{createDataFrame}, \link{read.json}, \link{table} -#' @seealso \url{https://spark.apache.org/docs/latest/sparkr.html#sparkr-dataframes} +#' @seealso \url{https://spark.apache.org/docs/latest/sparkr.html#sparkdataframe} #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df <- createDataFrame(faithful) #'} setClass("SparkDataFrame", @@ -77,8 +76,7 @@ dataFrame <- function(sdf, isCached = FALSE) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' printSchema(df) @@ -102,8 +100,7 @@ setMethod("printSchema", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' dfSchema <- schema(df) @@ -126,8 +123,7 @@ setMethod("schema", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' explain(df, TRUE) @@ -157,8 +153,7 @@ setMethod("explain", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' isLocal(df) @@ -182,8 +177,7 @@ setMethod("isLocal", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' showDF(df) @@ -207,8 +201,7 @@ setMethod("showDF", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' df @@ -234,8 +227,7 @@ setMethod("show", "SparkDataFrame", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' dtypes(df) @@ -261,8 +253,7 @@ setMethod("dtypes", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' columns(df) @@ -396,8 +387,7 @@ setMethod("coltypes", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' coltypes(df) <- c("character", "integer") @@ -432,7 +422,7 @@ setMethod("coltypes<-", #' Creates a temporary view using the given name. #' -#' Creates a new temporary view using a SparkDataFrame in the SQLContext. If a +#' Creates a new temporary view using a SparkDataFrame in the Spark Session. If a #' temporary view with the same name already exists, replaces it. #' #' @param x A SparkDataFrame @@ -444,8 +434,7 @@ setMethod("coltypes<-", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' createOrReplaceTempView(df, "json_df") @@ -469,8 +458,7 @@ setMethod("createOrReplaceTempView", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' registerTempTable(df, "json_df") @@ -498,8 +486,7 @@ setMethod("registerTempTable", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df <- read.df(path, "parquet") #' df2 <- read.df(path2, "parquet") #' createOrReplaceTempView(df, "table1") @@ -526,8 +513,7 @@ setMethod("insertInto", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' cache(df) @@ -554,8 +540,7 @@ setMethod("cache", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' persist(df, "MEMORY_AND_DISK") @@ -582,8 +567,7 @@ setMethod("persist", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' persist(df, "MEMORY_AND_DISK") @@ -617,8 +601,7 @@ setMethod("unpersist", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' newDF <- repartition(df, 2L) @@ -660,8 +643,7 @@ setMethod("repartition", #' @noRd #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' newRDD <- toJSON(df) @@ -688,8 +670,7 @@ setMethod("toJSON", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' write.json(df, "/tmp/sparkr-tmp/") @@ -742,8 +723,7 @@ setMethod("write.orc", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' write.parquet(df, "/tmp/sparkr-tmp1/") @@ -781,8 +761,7 @@ setMethod("saveAsParquetFile", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.txt" #' df <- read.text(path) #' write.text(df, "/tmp/sparkr-tmp/") @@ -806,8 +785,7 @@ setMethod("write.text", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' distinctDF <- distinct(df) @@ -842,8 +820,7 @@ setMethod("unique", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' collect(sample(df, FALSE, 0.5)) @@ -883,8 +860,7 @@ setMethod("sample_frac", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' count(df) @@ -913,8 +889,7 @@ setMethod("nrow", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' ncol(df) @@ -936,8 +911,7 @@ setMethod("ncol", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' dim(df) @@ -960,8 +934,7 @@ setMethod("dim", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' collected <- collect(df) @@ -1032,8 +1005,7 @@ setMethod("collect", #' @export #' @examples #' \dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' limitedDF <- limit(df, 10) @@ -1053,8 +1025,7 @@ setMethod("limit", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' take(df, 2) @@ -1082,8 +1053,7 @@ setMethod("take", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' head(df) @@ -1105,8 +1075,7 @@ setMethod("head", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' first(df) @@ -1126,8 +1095,7 @@ setMethod("first", #' @noRd #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' rdd <- toRDD(df) @@ -1662,8 +1630,7 @@ setMethod("select", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' selectExpr(df, "col1", "(col2 * 5) as newCol") @@ -1692,8 +1659,7 @@ setMethod("selectExpr", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' newDF <- withColumn(df, "newCol", df$col1 * 5) @@ -1721,8 +1687,7 @@ setMethod("withColumn", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' newDF <- mutate(df, newCol = df$col1 * 5, newCol2 = df$col1 * 2) @@ -1812,8 +1777,7 @@ setMethod("transform", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' newDF <- withColumnRenamed(df, "col1", "newCol1") @@ -1837,8 +1801,7 @@ setMethod("withColumnRenamed", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' newDF <- rename(df, col1 = df$newCol1) @@ -1881,8 +1844,7 @@ setClassUnion("characterOrColumn", c("character", "Column")) #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' arrange(df, df$col1) @@ -1957,8 +1919,7 @@ setMethod("orderBy", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' filter(df, "col1 > 0") @@ -1998,8 +1959,7 @@ setMethod("where", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' dropDuplicates(df) @@ -2045,8 +2005,7 @@ setMethod("dropDuplicates", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- read.json(path) #' df2 <- read.json(path2) #' join(df1, df2) # Performs a Cartesian @@ -2103,8 +2062,7 @@ setMethod("join", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- read.json(path) #' df2 <- read.json(path2) #' merge(df1, df2) # Performs a Cartesian @@ -2235,8 +2193,7 @@ generateAliasesForIntersectedCols <- function (x, intersectedColNames, suffix) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- read.json(path) #' df2 <- read.json(path2) #' unioned <- unionAll(df, df2) @@ -2279,8 +2236,7 @@ setMethod("rbind", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- read.json(path) #' df2 <- read.json(path2) #' intersectDF <- intersect(df, df2) @@ -2306,8 +2262,7 @@ setMethod("intersect", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- read.json(path) #' df2 <- read.json(path2) #' exceptDF <- except(df, df2) @@ -2349,8 +2304,7 @@ setMethod("except", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' write.df(df, "myfile", "parquet", "overwrite") @@ -2408,8 +2362,7 @@ setMethod("saveDF", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' saveAsTable(df, "myfile") @@ -2445,8 +2398,7 @@ setMethod("saveAsTable", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' describe(df) @@ -2501,10 +2453,9 @@ setMethod("summary", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlCtx <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" -#' df <- read.json(sqlCtx, path) +#' df <- read.json(path) #' dropna(df) #' } setMethod("dropna", @@ -2555,10 +2506,9 @@ setMethod("na.omit", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlCtx <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" -#' df <- read.json(sqlCtx, path) +#' df <- read.json(path) #' fillna(df, 1) #' fillna(df, list("age" = 20, "name" = "unknown")) #' } @@ -2769,10 +2719,9 @@ setMethod("str", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlCtx <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" -#' df <- read.json(sqlCtx, path) +#' df <- read.json(path) #' drop(df, "col1") #' drop(df, c("col1", "col2")) #' drop(df, df$col1) @@ -2943,8 +2892,7 @@ setMethod("histogram", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' jdbcUrl <- "jdbc:mysql://localhost:3306/databasename" #' write.jdbc(df, jdbcUrl, "table", user = "username", password = "password") #' } @@ -2972,8 +2920,7 @@ setMethod("write.jdbc", #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df <- createDataFrame(data.frame(id = 1:1000)) #' df_list <- randomSplit(df, c(2, 3, 5), 0) #' # df_list contains 3 SparkDataFrames with each having about 200, 300 and 500 rows respectively diff --git a/R/pkg/R/SQLContext.R b/R/pkg/R/SQLContext.R index b7e1c062c7..b846b3dec2 100644 --- a/R/pkg/R/SQLContext.R +++ b/R/pkg/R/SQLContext.R @@ -126,8 +126,7 @@ getDefaultSqlSource <- function() { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- as.DataFrame(iris) #' df2 <- as.DataFrame(list(3,4,5,6)) #' df3 <- createDataFrame(iris) @@ -238,8 +237,7 @@ as.DataFrame <- function(x, ...) { #' @noRd #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' rdd <- lapply(parallelize(sc, 1:10), function(x) list(a=x, b=as.character(x))) #' df <- toDF(rdd) #'} @@ -261,8 +259,7 @@ setMethod("toDF", signature(x = "RDD"), #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' df <- jsonFile(path) @@ -309,8 +306,7 @@ jsonFile <- function(x, ...) { #' @noRd #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' rdd <- texFile(sc, "path/to/json") #' df <- jsonRDD(sqlContext, rdd) #'} @@ -401,8 +397,7 @@ parquetFile <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.txt" #' df <- read.text(path) #' } @@ -432,8 +427,7 @@ read.text <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' createOrReplaceTempView(df, "table") @@ -464,8 +458,7 @@ sql <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' createOrReplaceTempView(df, "table") @@ -489,8 +482,7 @@ tableToDF <- function(tableName) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' tables("hive") #' } #' @name tables @@ -516,8 +508,7 @@ tables <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' tableNames("hive") #' } #' @name tableNames @@ -545,8 +536,7 @@ tableNames <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' createOrReplaceTempView(df, "table") @@ -575,8 +565,7 @@ cacheTable <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' path <- "path/to/file.json" #' df <- read.json(path) #' createOrReplaceTempView(df, "table") @@ -629,8 +618,7 @@ clearCache <- function() { #' @export #' @examples #' \dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df <- read.df(path, "parquet") #' createOrReplaceTempView(df, "table") #' dropTempTable("table") @@ -694,8 +682,7 @@ dropTempView <- function(viewName) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' df1 <- read.df("path/to/file.json", source = "json") #' schema <- structType(structField("name", "string"), #' structField("info", "map<string,double>")) @@ -758,9 +745,8 @@ loadDF <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) -#' df <- sparkRSQL.createExternalTable("myjson", path="path/to/json", source="json") +#' sparkR.session() +#' df <- createExternalTable("myjson", path="path/to/json", source="json") #' } #' @name createExternalTable #' @method createExternalTable default @@ -806,8 +792,7 @@ createExternalTable <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' jdbcUrl <- "jdbc:mysql://localhost:3306/databasename" #' df <- read.jdbc(jdbcUrl, "table", predicates = list("field<=123"), user = "username") #' df2 <- read.jdbc(jdbcUrl, "table2", partitionColumn = "index", lowerBound = 0, diff --git a/R/pkg/R/mllib.R b/R/pkg/R/mllib.R index ba2eee2fca..2127daee18 100644 --- a/R/pkg/R/mllib.R +++ b/R/pkg/R/mllib.R @@ -67,8 +67,7 @@ setClass("KMeansModel", representation(jobj = "jobj")) #' @export #' @examples #' \dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' data(iris) #' df <- createDataFrame(iris) #' model <- spark.glm(df, Sepal_Length ~ Sepal_Width, family="gaussian") @@ -115,8 +114,7 @@ setMethod( #' @export #' @examples #' \dontrun{ -#' sc <- sparkR.init() -#' sqlContext <- sparkRSQL.init(sc) +#' sparkR.session() #' data(iris) #' df <- createDataFrame(iris) #' model <- glm(Sepal_Length ~ Sepal_Width, df, family="gaussian") diff --git a/R/pkg/R/schema.R b/R/pkg/R/schema.R index 039aa008b3..89a2cfac3c 100644 --- a/R/pkg/R/schema.R +++ b/R/pkg/R/schema.R @@ -29,11 +29,11 @@ #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlCtx <- sparkRSQL.init(sc) -#' rdd <- lapply(parallelize(sc, 1:10), function(x) { list(x, as.character(x)) }) -#' schema <- structType(structField("a", "integer"), structField("b", "string")) -#' df <- createDataFrame(sqlCtx, rdd, schema) +#' schema <- structType(structField("a", "integer"), structField("c", "string"), +#' structField("avg", "double")) +#' df1 <- gapply(df, list("a", "c"), +#' function(key, x) { y <- data.frame(key, mean(x$b), stringsAsFactors = FALSE) }, +#' schema) #' } structType <- function(x, ...) { UseMethod("structType", x) @@ -90,13 +90,13 @@ print.structType <- function(x, ...) { #' @export #' @examples #'\dontrun{ -#' sc <- sparkR.init() -#' sqlCtx <- sparkRSQL.init(sc) -#' rdd <- lapply(parallelize(sc, 1:10), function(x) { list(x, as.character(x)) }) -#' field1 <- structField("a", "integer", TRUE) -#' field2 <- structField("b", "string", TRUE) -#' schema <- structType(field1, field2) -#' df <- createDataFrame(sqlCtx, rdd, schema) +#' field1 <- structField("a", "integer") +#' field2 <- structField("c", "string") +#' field3 <- structField("avg", "double") +#' schema <- structType(field1, field2, field3) +#' df1 <- gapply(df, list("a", "c"), +#' function(key, x) { y <- data.frame(key, mean(x$b), stringsAsFactors = FALSE) }, +#' schema) #' } structField <- function(x, ...) { diff --git a/R/pkg/R/sparkR.R b/R/pkg/R/sparkR.R index 0dfd7b7530..d05660ccf6 100644 --- a/R/pkg/R/sparkR.R +++ b/R/pkg/R/sparkR.R @@ -89,9 +89,7 @@ sparkR.session.stop <- function() { #' (Deprecated) Initialize a new Spark Context. #' -#' This function initializes a new SparkContext. For details on how to initialize -#' and use SparkR, refer to SparkR programming guide at -#' \url{http://spark.apache.org/docs/latest/sparkr.html#starting-up-sparkcontext-sqlcontext}. +#' This function initializes a new SparkContext. #' #' @param master The Spark master URL #' @param appName Application name to register with cluster manager @@ -312,6 +310,9 @@ sparkRHive.init <- function(jsc = NULL) { #' Additional Spark properties can be set (...), and these named parameters take priority over #' over values in master, appName, named lists of sparkConfig. #' +#' For details on how to initialize and use SparkR, refer to SparkR programming guide at +#' \url{http://spark.apache.org/docs/latest/sparkr.html#starting-up-sparksession}. +#' #' @param master The Spark master URL #' @param appName Application name to register with cluster manager #' @param sparkHome Spark Home directory diff --git a/docs/sparkr.md b/docs/sparkr.md index 961bd323fa..023bbcd39c 100644 --- a/docs/sparkr.md +++ b/docs/sparkr.md @@ -14,29 +14,24 @@ supports operations like selection, filtering, aggregation etc. (similar to R da [dplyr](https://github.com/hadley/dplyr)) but on large datasets. SparkR also supports distributed machine learning using MLlib. -# SparkR DataFrames +# SparkDataFrame -A DataFrame is a distributed collection of data organized into named columns. It is conceptually +A SparkDataFrame is a distributed collection of data organized into named columns. It is conceptually equivalent to a table in a relational database or a data frame in R, but with richer -optimizations under the hood. DataFrames can be constructed from a wide array of sources such as: +optimizations under the hood. SparkDataFrames can be constructed from a wide array of sources such as: structured data files, tables in Hive, external databases, or existing local R data frames. All of the examples on this page use sample data included in R or the Spark distribution and can be run using the `./bin/sparkR` shell. -## Starting Up: SparkContext, SQLContext +## Starting Up: SparkSession <div data-lang="r" markdown="1"> -The entry point into SparkR is the `SparkContext` which connects your R program to a Spark cluster. -You can create a `SparkContext` using `sparkR.init` and pass in options such as the application name -, any spark packages depended on, etc. Further, to work with DataFrames we will need a `SQLContext`, -which can be created from the SparkContext. If you are working from the `sparkR` shell, the -`SQLContext` and `SparkContext` should already be created for you, and you would not need to call -`sparkR.init`. +The entry point into SparkR is the `SparkSession` which connects your R program to a Spark cluster. +You can create a `SparkSession` using `sparkR.session` and pass in options such as the application name, any spark packages depended on, etc. Further, you can also work with SparkDataFrames via `SparkSession`. If you are working from the `sparkR` shell, the `SparkSession` should already be created for you, and you would not need to call `sparkR.session`. <div data-lang="r" markdown="1"> {% highlight r %} -sc <- sparkR.init() -sqlContext <- sparkRSQL.init(sc) +sparkR.session() {% endhighlight %} </div> @@ -45,13 +40,13 @@ sqlContext <- sparkRSQL.init(sc) You can also start SparkR from RStudio. You can connect your R program to a Spark cluster from RStudio, R shell, Rscript or other R IDEs. To start, make sure SPARK_HOME is set in environment (you can check [Sys.getenv](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Sys.getenv.html)), -load the SparkR package, and call `sparkR.init` as below. In addition to calling `sparkR.init`, you -could also specify certain Spark driver properties. Normally these +load the SparkR package, and call `sparkR.session` as below. In addition to calling `sparkR.session`, + you could also specify certain Spark driver properties. Normally these [Application properties](configuration.html#application-properties) and [Runtime Environment](configuration.html#runtime-environment) cannot be set programmatically, as the driver JVM process would have been started, in this case SparkR takes care of this for you. To set -them, pass them as you would other configuration properties in the `sparkEnvir` argument to -`sparkR.init()`. +them, pass them as you would other configuration properties in the `sparkConfig` argument to +`sparkR.session()`. <div data-lang="r" markdown="1"> {% highlight r %} @@ -59,11 +54,11 @@ if (nchar(Sys.getenv("SPARK_HOME")) < 1) { Sys.setenv(SPARK_HOME = "/home/spark") } library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib"))) -sc <- sparkR.init(master = "local[*]", sparkEnvir = list(spark.driver.memory="2g")) +sc <- sparkR.session(master = "local[*]", sparkConfig = list(spark.driver.memory="2g")) {% endhighlight %} </div> -The following options can be set in `sparkEnvir` with `sparkR.init` from RStudio: +The following Spark driver properties can be set in `sparkConfig` with `sparkR.session` from RStudio: <table class="table"> <tr><th>Property Name</th><th>Property group</th><th><code>spark-submit</code> equivalent</th></tr> @@ -91,17 +86,17 @@ The following options can be set in `sparkEnvir` with `sparkR.init` from RStudio </div> -## Creating DataFrames -With a `SQLContext`, applications can create `DataFrame`s from a local R data frame, from a [Hive table](sql-programming-guide.html#hive-tables), or from other [data sources](sql-programming-guide.html#data-sources). +## Creating SparkDataFrames +With a `SparkSession`, applications can create `SparkDataFrame`s from a local R data frame, from a [Hive table](sql-programming-guide.html#hive-tables), or from other [data sources](sql-programming-guide.html#data-sources). ### From local data frames -The simplest way to create a data frame is to convert a local R data frame into a SparkR DataFrame. Specifically we can use `createDataFrame` and pass in the local R data frame to create a SparkR DataFrame. As an example, the following creates a `DataFrame` based using the `faithful` dataset from R. +The simplest way to create a data frame is to convert a local R data frame into a SparkDataFrame. Specifically we can use `as.DataFrame` or `createDataFrame` and pass in the local R data frame to create a SparkDataFrame. As an example, the following creates a `SparkDataFrame` based using the `faithful` dataset from R. <div data-lang="r" markdown="1"> {% highlight r %} -df <- createDataFrame(sqlContext, faithful) +df <- as.DataFrame(faithful) -# Displays the content of the DataFrame to stdout +# Displays the first part of the SparkDataFrame head(df) ## eruptions waiting ##1 3.600 79 @@ -113,16 +108,15 @@ head(df) ### From Data Sources -SparkR supports operating on a variety of data sources through the `DataFrame` interface. This section describes the general methods for loading and saving data using Data Sources. You can check the Spark SQL programming guide for more [specific options](sql-programming-guide.html#manually-specifying-options) that are available for the built-in data sources. +SparkR supports operating on a variety of data sources through the `SparkDataFrame` interface. This section describes the general methods for loading and saving data using Data Sources. You can check the Spark SQL programming guide for more [specific options](sql-programming-guide.html#manually-specifying-options) that are available for the built-in data sources. -The general method for creating DataFrames from data sources is `read.df`. This method takes in the `SQLContext`, the path for the file to load and the type of data source. SparkR supports reading JSON, CSV and Parquet files natively and through [Spark Packages](http://spark-packages.org/) you can find data source connectors for popular file formats like [Avro](http://spark-packages.org/package/databricks/spark-avro). These packages can either be added by +The general method for creating SparkDataFrames from data sources is `read.df`. This method takes in the path for the file to load and the type of data source, and the currently active SparkSession will be used automatically. SparkR supports reading JSON, CSV and Parquet files natively and through [Spark Packages](http://spark-packages.org/) you can find data source connectors for popular file formats like [Avro](http://spark-packages.org/package/databricks/spark-avro). These packages can either be added by specifying `--packages` with `spark-submit` or `sparkR` commands, or if creating context through `init` you can specify the packages with the `packages` argument. <div data-lang="r" markdown="1"> {% highlight r %} -sc <- sparkR.init(sparkPackages="com.databricks:spark-avro_2.11:2.0.1") -sqlContext <- sparkRSQL.init(sc) +sc <- sparkR.session(sparkPackages="com.databricks:spark-avro_2.11:3.0.0") {% endhighlight %} </div> @@ -131,7 +125,7 @@ We can see how to use data sources using an example JSON input file. Note that t <div data-lang="r" markdown="1"> {% highlight r %} -people <- read.df(sqlContext, "./examples/src/main/resources/people.json", "json") +people <- read.df("./examples/src/main/resources/people.json", "json") head(people) ## age name ##1 NA Michael @@ -147,8 +141,8 @@ printSchema(people) {% endhighlight %} </div> -The data sources API can also be used to save out DataFrames into multiple file formats. For example we can save the DataFrame from the previous example -to a Parquet file using `write.df` (Until Spark 1.6, the default mode for writes was `append`. It was changed in Spark 1.7 to `error` to match the Scala API) +The data sources API can also be used to save out SparkDataFrames into multiple file formats. For example we can save the SparkDataFrame from the previous example +to a Parquet file using `write.df`. <div data-lang="r" markdown="1"> {% highlight r %} @@ -158,20 +152,19 @@ write.df(people, path="people.parquet", source="parquet", mode="overwrite") ### From Hive tables -You can also create SparkR DataFrames from Hive tables. To do this we will need to create a HiveContext which can access tables in the Hive MetaStore. Note that Spark should have been built with [Hive support](building-spark.html#building-with-hive-and-jdbc-support) and more details on the difference between SQLContext and HiveContext can be found in the [SQL programming guide](sql-programming-guide.html#starting-point-sqlcontext). +You can also create SparkDataFrames from Hive tables. To do this we will need to create a SparkSession with Hive support which can access tables in the Hive MetaStore. Note that Spark should have been built with [Hive support](building-spark.html#building-with-hive-and-jdbc-support) and more details can be found in the [SQL programming guide](sql-programming-guide.html#starting-point-sqlcontext). In SparkR, by default it will attempt to create a SparkSession with Hive support enabled (`enableHiveSupport = TRUE`). <div data-lang="r" markdown="1"> {% highlight r %} -# sc is an existing SparkContext. -hiveContext <- sparkRHive.init(sc) +sparkR.session() -sql(hiveContext, "CREATE TABLE IF NOT EXISTS src (key INT, value STRING)") -sql(hiveContext, "LOAD DATA LOCAL INPATH 'examples/src/main/resources/kv1.txt' INTO TABLE src") +sql("CREATE TABLE IF NOT EXISTS src (key INT, value STRING)") +sql("LOAD DATA LOCAL INPATH 'examples/src/main/resources/kv1.txt' INTO TABLE src") # Queries can be expressed in HiveQL. -results <- sql(hiveContext, "FROM src SELECT key, value") +results <- sql("FROM src SELECT key, value") -# results is now a DataFrame +# results is now a SparkDataFrame head(results) ## key value ## 1 238 val_238 @@ -181,19 +174,19 @@ head(results) {% endhighlight %} </div> -## DataFrame Operations +## SparkDataFrame Operations -SparkR DataFrames support a number of functions to do structured data processing. +SparkDataFrames support a number of functions to do structured data processing. Here we include some basic examples and a complete list can be found in the [API](api/R/index.html) docs: ### Selecting rows, columns <div data-lang="r" markdown="1"> {% highlight r %} -# Create the DataFrame -df <- createDataFrame(sqlContext, faithful) +# Create the SparkDataFrame +df <- as.DataFrame(faithful) -# Get basic information about the DataFrame +# Get basic information about the SparkDataFrame df ## SparkDataFrame[eruptions:double, waiting:double] @@ -207,7 +200,7 @@ head(select(df, df$eruptions)) # You can also pass in column name as strings head(select(df, "eruptions")) -# Filter the DataFrame to only retain rows with wait times shorter than 50 mins +# Filter the SparkDataFrame to only retain rows with wait times shorter than 50 mins head(filter(df, df$waiting < 50)) ## eruptions waiting ##1 1.750 47 @@ -251,7 +244,7 @@ SparkR also provides a number of functions that can directly applied to columns {% highlight r %} # Convert waiting time from hours to seconds. -# Note that we can assign this to a new column in the same DataFrame +# Note that we can assign this to a new column in the same SparkDataFrame df$waiting_secs <- df$waiting * 60 head(df) ## eruptions waiting waiting_secs @@ -263,19 +256,19 @@ head(df) </div> ## Running SQL Queries from SparkR -A SparkR DataFrame can also be registered as a temporary table in Spark SQL and registering a DataFrame as a table allows you to run SQL queries over its data. -The `sql` function enables applications to run SQL queries programmatically and returns the result as a `DataFrame`. +A SparkDataFrame can also be registered as a temporary view in Spark SQL and that allows you to run SQL queries over its data. +The `sql` function enables applications to run SQL queries programmatically and returns the result as a `SparkDataFrame`. <div data-lang="r" markdown="1"> {% highlight r %} # Load a JSON file -people <- read.df(sqlContext, "./examples/src/main/resources/people.json", "json") +people <- read.df("./examples/src/main/resources/people.json", "json") -# Register this DataFrame as a table. -registerTempTable(people, "people") +# Register this SparkDataFrame as a temporary view. +createOrReplaceTempView(people, "people") # SQL statements can be run by using the sql method -teenagers <- sql(sqlContext, "SELECT name FROM people WHERE age >= 13 AND age <= 19") +teenagers <- sql("SELECT name FROM people WHERE age >= 13 AND age <= 19") head(teenagers) ## name ##1 Justin @@ -353,4 +346,8 @@ You can inspect the search path in R with [`search()`](https://stat.ethz.ch/R-ma - The method `table` has been removed and replaced by `tableToDF`. - The class `DataFrame` has been renamed to `SparkDataFrame` to avoid name conflicts. - - The `sqlContext` parameter is no longer required for these functions: `createDataFrame`, `as.DataFrame`, `read.json`, `jsonFile`, `read.parquet`, `parquetFile`, `read.text`, `sql`, `tables`, `tableNames`, `cacheTable`, `uncacheTable`, `clearCache`, `dropTempTable`, `read.df`, `loadDF`, `createExternalTable` + - Spark's `SQLContext` and `HiveContext` have been deprecated to be replaced by `SparkSession`. Instead of `sparkR.init()`, call `sparkR.session()` in its place to instantiate the SparkSession. Once that is done, that currently active SparkSession will be used for SparkDataFrame operations. + - The parameter `sparkExecutorEnv` is not supported by `sparkR.session`. To set environment for the executors, set Spark config properties with the prefix "spark.executorEnv.VAR_NAME", for example, "spark.executorEnv.PATH" + - The `sqlContext` parameter is no longer required for these functions: `createDataFrame`, `as.DataFrame`, `read.json`, `jsonFile`, `read.parquet`, `parquetFile`, `read.text`, `sql`, `tables`, `tableNames`, `cacheTable`, `uncacheTable`, `clearCache`, `dropTempTable`, `read.df`, `loadDF`, `createExternalTable`. + - The method `registerTempTable` has been deprecated to be replaced by `createOrReplaceTempView`. + - The method `dropTempTable` has been deprecated to be replaced by `dropTempView`. diff --git a/examples/src/main/r/data-manipulation.R b/examples/src/main/r/data-manipulation.R index badb98bc78..371335a62e 100644 --- a/examples/src/main/r/data-manipulation.R +++ b/examples/src/main/r/data-manipulation.R @@ -17,7 +17,7 @@ # For this example, we shall use the "flights" dataset # The dataset consists of every flight departing Houston in 2011. -# The data set is made up of 227,496 rows x 14 columns. +# The data set is made up of 227,496 rows x 14 columns. # To run this example use # ./bin/spark-submit examples/src/main/r/data-manipulation.R <path_to_csv> @@ -33,11 +33,8 @@ if (length(args) != 1) { q("no") } -## Initialize SparkContext -sc <- sparkR.init(appName = "SparkR-data-manipulation-example") - -## Initialize SQLContext -sqlContext <- sparkRSQL.init(sc) +## Initialize SparkSession +sparkR.session(appName = "SparkR-data-manipulation-example") flightsCsvPath <- args[[1]] @@ -46,7 +43,7 @@ flights_df <- read.csv(flightsCsvPath, header = TRUE) flights_df$date <- as.Date(flights_df$date) ## Filter flights whose destination is San Francisco and write to a local data frame -SFO_df <- flights_df[flights_df$dest == "SFO", ] +SFO_df <- flights_df[flights_df$dest == "SFO", ] # Convert the local data frame into a SparkDataFrame SFO_DF <- createDataFrame(SFO_df) @@ -102,5 +99,5 @@ if("magrittr" %in% rownames(installed.packages())) { head(dailyDelayDF) } -# Stop the SparkContext now -sparkR.stop() +# Stop the SparkSession now +sparkR.session.stop() diff --git a/examples/src/main/r/dataframe.R b/examples/src/main/r/dataframe.R index 0434705717..a377d6e864 100644 --- a/examples/src/main/r/dataframe.R +++ b/examples/src/main/r/dataframe.R @@ -17,9 +17,8 @@ library(SparkR) -# Initialize SparkContext and SQLContext -sc <- sparkR.init(appName="SparkR-DataFrame-example") -sqlContext <- sparkRSQL.init(sc) +# Initialize SparkSession +sc <- sparkR.session(appName="SparkR-DataFrame-example") # Create a simple local data.frame localDF <- data.frame(name=c("John", "Smith", "Sarah"), age=c(19, 23, 18)) @@ -44,14 +43,14 @@ printSchema(peopleDF) # Register this DataFrame as a table. createOrReplaceTempView(peopleDF, "people") -# SQL statements can be run by using the sql methods provided by sqlContext +# SQL statements can be run by using the sql methods teenagers <- sql("SELECT name FROM people WHERE age >= 13 AND age <= 19") # Call collect to get a local data.frame teenagersLocalDF <- collect(teenagers) -# Print the teenagers in our dataset +# Print the teenagers in our dataset print(teenagersLocalDF) -# Stop the SparkContext now -sparkR.stop() +# Stop the SparkSession now +sparkR.session.stop() diff --git a/examples/src/main/r/ml.R b/examples/src/main/r/ml.R index 495f392c26..940c98dcb9 100644 --- a/examples/src/main/r/ml.R +++ b/examples/src/main/r/ml.R @@ -21,14 +21,13 @@ # Load SparkR library into your R session library(SparkR) -# Initialize SparkContext and SQLContext -sc <- sparkR.init(appName="SparkR-ML-example") -sqlContext <- sparkRSQL.init(sc) +# Initialize SparkSession +sparkR.session(appName="SparkR-ML-example") # $example on$ ############################ spark.glm and glm ############################################## -irisDF <- suppressWarnings(createDataFrame(sqlContext, iris)) +irisDF <- suppressWarnings(createDataFrame(iris)) # Fit a generalized linear model of family "gaussian" with spark.glm gaussianDF <- irisDF gaussianTestDF <- irisDF @@ -62,7 +61,7 @@ showDF(binomialPredictions) library(survival) # Fit an accelerated failure time (AFT) survival regression model with spark.survreg -ovarianDF <- suppressWarnings(createDataFrame(sqlContext, ovarian)) +ovarianDF <- suppressWarnings(createDataFrame(ovarian)) aftDF <- ovarianDF aftTestDF <- ovarianDF aftModel <- spark.survreg(aftDF, Surv(futime, fustat) ~ ecog_ps + rx) @@ -78,7 +77,7 @@ showDF(aftPredictions) # Fit a Bernoulli naive Bayes model with spark.naiveBayes titanic <- as.data.frame(Titanic) -titanicDF <- suppressWarnings(createDataFrame(sqlContext, titanic[titanic$Freq > 0, -5])) +titanicDF <- createDataFrame(titanic[titanic$Freq > 0, -5]) nbDF <- titanicDF nbTestDF <- titanicDF nbModel <- spark.naiveBayes(nbDF, Survived ~ Class + Sex + Age) @@ -93,7 +92,7 @@ showDF(nbPredictions) ############################ spark.kmeans ############################################## # Fit a k-means model with spark.kmeans -irisDF <- suppressWarnings(createDataFrame(sqlContext, iris)) +irisDF <- suppressWarnings(createDataFrame(iris)) kmeansDF <- irisDF kmeansTestDF <- irisDF kmeansModel <- spark.kmeans(kmeansDF, ~ Sepal_Length + Sepal_Width + Petal_Length + Petal_Width, @@ -111,7 +110,7 @@ showDF(kmeansPredictions) ############################ model read/write ############################################## -irisDF <- suppressWarnings(createDataFrame(sqlContext, iris)) +irisDF <- suppressWarnings(createDataFrame(iris)) # Fit a generalized linear model of family "gaussian" with spark.glm gaussianDF <- irisDF gaussianTestDF <- irisDF @@ -139,11 +138,11 @@ train <- function(family) { model <- glm(Sepal.Length ~ Sepal.Width + Species, iris, family = family) summary(model) } -model.summaries <- spark.lapply(sc, families, train) +model.summaries <- spark.lapply(families, train) # Print the summary of each model print(model.summaries) -# Stop the SparkContext now -sparkR.stop() +# Stop the SparkSession now +sparkR.session.stop() |