appName(name: String): Builder
Builder — Building SparkSession using Fluent API
Builder is the fluent API to create a SparkSession.
| Method | Description |
|---|---|
|
|
Enables Hive support
|
|
Gets the current SparkSession or creates a new one.
|
|
|
|
Access to the SparkSessionExtensions
|
Builder is available using the builder object method of a SparkSession.
import org.apache.spark.sql.SparkSession
val spark = SparkSession.builder
.appName("My Spark Application") // optional and will be autogenerated if not specified
.master("local[*]") // only for demo and testing purposes, use spark-submit instead
.enableHiveSupport() // self-explanatory, isn't it?
.config("spark.sql.warehouse.dir", "target/spark-warehouse")
.withExtensions { extensions =>
extensions.injectResolutionRule { session =>
...
}
extensions.injectOptimizerRule { session =>
...
}
}
.getOrCreate
|
Note
|
You can have multiple SparkSessions in a single Spark application for different data catalogs (through relational entities).
|
| Name | Description |
|---|---|
|
Used when…FIXME |
|
Used when…FIXME |
Getting Or Creating SparkSession Instance — getOrCreate Method
getOrCreate(): SparkSession
getOrCreate…FIXME
Enabling Hive Support — enableHiveSupport Method
enableHiveSupport(): Builder
enableHiveSupport enables Hive support (that allows running structured queries on Hive tables, a persistent Hive metastore, support for Hive serdes and user-defined functions).
|
Note
|
You do not need any existing Hive installation to use Spark’s Hive support. Refer to SharedState. |
Internally, enableHiveSupport checks whether the Hive classes are available or not. If so, enableHiveSupport sets spark.sql.catalogImplementation internal configuration property to hive. Otherwise, enableHiveSupport throws an IllegalArgumentException:
Unable to instantiate SparkSession with Hive support because Hive classes are not found.
hiveClassesArePresent Method
hiveClassesArePresent: Boolean
hiveClassesArePresent loads and initializes org.apache.spark.sql.hive.HiveSessionStateBuilder and org.apache.hadoop.hive.conf.HiveConf classes from the current classloader.
hiveClassesArePresent returns true when the initialization succeeded, and false otherwise (due to ClassNotFoundException or NoClassDefFoundError errors).
|
Note
|
|
withExtensions Method
withExtensions(f: SparkSessionExtensions => Unit): Builder
withExtensions simply executes the input f function with the SparkSessionExtensions.