Skip to content

Commit bd854da

Browse files
authored
Merge pull request #127 from Jolanrensen/defaultSparkMasterValue
Default master value to first check the system variables.
2 parents e81292e + bfbadfe commit bd854da

File tree

1 file changed

+17
-5
lines changed
  • kotlin-spark-api/3.2/src/main/kotlin/org/jetbrains/kotlinx/spark/api

1 file changed

+17
-5
lines changed

kotlin-spark-api/3.2/src/main/kotlin/org/jetbrains/kotlinx/spark/api/SparkHelper.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,27 @@
1919
*/
2020
package org.jetbrains.kotlinx.spark.api
2121

22+
import org.apache.spark.SparkConf
2223
import org.apache.spark.sql.SparkSession.Builder
2324
import org.apache.spark.sql.UDFRegistration
2425
import org.jetbrains.kotlinx.spark.api.SparkLogLevel.ERROR
2526

2627
/**
27-
* Wrapper for spark creation which allows to set different spark params
28+
* Wrapper for spark creation which allows setting different spark params.
2829
*
2930
* @param props spark options, value types are runtime-checked for type-correctness
30-
* @param master [SparkSession.Builder.master]
31-
* @param appName [SparkSession.Builder.appName]
31+
* @param master Sets the Spark master URL to connect to, such as "local" to run locally, "local[4]" to
32+
* run locally with 4 cores, or "spark://master:7077" to run on a Spark standalone cluster. By default, it
33+
* tries to get the system value "spark.master", otherwise it uses "local[*]"
34+
* @param appName Sets a name for the application, which will be shown in the Spark web UI.
35+
* If no application name is set, a randomly generated name will be used.
36+
* @param logLevel Control our logLevel. This overrides any user-defined log settings.
3237
* @param func function which will be executed in context of [KSparkSession] (it means that `this` inside block will point to [KSparkSession])
3338
*/
3439
@JvmOverloads
3540
inline fun withSpark(
3641
props: Map<String, Any> = emptyMap(),
37-
master: String = "local[*]",
42+
master: String = SparkConf().get("spark.master", "local[*]"),
3843
appName: String = "Kotlin Spark Sample",
3944
logLevel: SparkLogLevel = ERROR,
4045
func: KSparkSession.() -> Unit,
@@ -58,10 +63,17 @@ inline fun withSpark(
5863

5964
}
6065

66+
/**
67+
* Wrapper for spark creation which allows setting different spark params.
68+
*
69+
* @param builder A [SparkSession.Builder] object, configured how you want.
70+
* @param logLevel Control our logLevel. This overrides any user-defined log settings.
71+
* @param func function which will be executed in context of [KSparkSession] (it means that `this` inside block will point to [KSparkSession])
72+
*/
6173
@JvmOverloads
6274
inline fun withSpark(builder: Builder, logLevel: SparkLogLevel = ERROR, func: KSparkSession.() -> Unit) {
6375
builder
64-
.orCreate
76+
.getOrCreate()
6577
.apply {
6678
KSparkSession(this).apply {
6779
sparkContext.setLogLevel(logLevel)

0 commit comments

Comments
 (0)