8c198e246d
## What changes were proposed in this pull request? This PR introduces the new SparkSession API for SparkR. `sparkR.session.getOrCreate()` and `sparkR.session.stop()` "getOrCreate" is a bit unusual in R but it's important to name this clearly. SparkR implementation should - SparkSession is the main entrypoint (vs SparkContext; due to limited functionality supported with SparkContext in SparkR) - SparkSession replaces SQLContext and HiveContext (both a wrapper around SparkSession, and because of API changes, supporting all 3 would be a lot more work) - Changes to SparkSession is mostly transparent to users due to SPARK-10903 - Full backward compatibility is expected - users should be able to initialize everything just in Spark 1.6.1 (`sparkR.init()`), but with deprecation warning - Mostly cosmetic changes to parameter list - users should be able to move to `sparkR.session.getOrCreate()` easily - An advanced syntax with named parameters (aka varargs aka "...") is supported; that should be closer to the Builder syntax that is in Scala/Python (which unfortunately does not work in R because it will look like this: `enableHiveSupport(config(config(master(appName(builder(), "foo"), "local"), "first", "value"), "next, "value"))` - Updating config on an existing SparkSession is supported, the behavior is the same as Python, in which config is applied to both SparkContext and SparkSession - Some SparkSession changes are not matched in SparkR, mostly because it would be breaking API change: `catalog` object, `createOrReplaceTempView` - Other SQLContext workarounds are replicated in SparkR, eg. `tables`, `tableNames` - `sparkR` shell is updated to use the SparkSession entrypoint (`sqlContext` is removed, just like with Scale/Python) - All tests are updated to use the SparkSession entrypoint - A bug in `read.jdbc` is fixed TODO - [x] Add more tests - [ ] Separate PR - update all roxygen2 doc coding example - [ ] Separate PR - update SparkR programming guide ## How was this patch tested? unit tests, manual tests shivaram sun-rui rxin Author: Felix Cheung <felixcheung_m@hotmail.com> Author: felixcheung <felixcheung_m@hotmail.com> Closes #13635 from felixcheung/rsparksession.
48 lines
1.7 KiB
R
48 lines
1.7 KiB
R
#
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
# this work for additional information regarding copyright ownership.
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
|
|
.First <- function() {
|
|
home <- Sys.getenv("SPARK_HOME")
|
|
.libPaths(c(file.path(home, "R", "lib"), .libPaths()))
|
|
Sys.setenv(NOAWT = 1)
|
|
|
|
# Make sure SparkR package is the last loaded one
|
|
old <- getOption("defaultPackages")
|
|
options(defaultPackages = c(old, "SparkR"))
|
|
|
|
spark <- SparkR::sparkR.session()
|
|
assign("spark", spark, envir = .GlobalEnv)
|
|
sc <- SparkR:::callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getJavaSparkContext", spark)
|
|
assign("sc", sc, envir = .GlobalEnv)
|
|
sparkVer <- SparkR:::callJMethod(sc, "version")
|
|
cat("\n Welcome to")
|
|
cat("\n")
|
|
cat(" ____ __", "\n")
|
|
cat(" / __/__ ___ _____/ /__", "\n")
|
|
cat(" _\\ \\/ _ \\/ _ `/ __/ '_/", "\n")
|
|
cat(" /___/ .__/\\_,_/_/ /_/\\_\\")
|
|
if (nchar(sparkVer) == 0) {
|
|
cat("\n")
|
|
} else {
|
|
cat(" version ", sparkVer, "\n")
|
|
}
|
|
cat(" /_/", "\n")
|
|
cat("\n")
|
|
|
|
cat("\n SparkSession available as 'spark'.\n")
|
|
}
|