19
19
*/
20
20
package org.jetbrains.kotlinx.spark.api
21
21
22
+ import org.apache.spark.SparkConf
22
23
import org.apache.spark.sql.SparkSession.Builder
23
24
import org.apache.spark.sql.UDFRegistration
24
25
import org.jetbrains.kotlinx.spark.api.SparkLogLevel.ERROR
25
26
26
27
/* *
27
- * Wrapper for spark creation which allows to set different spark params
28
+ * Wrapper for spark creation which allows setting different spark params.
28
29
*
29
30
* @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.
32
37
* @param func function which will be executed in context of [KSparkSession] (it means that `this` inside block will point to [KSparkSession])
33
38
*/
34
39
@JvmOverloads
35
40
inline fun withSpark (
36
41
props : Map <String , Any > = emptyMap(),
37
- master : String = " local[*]",
42
+ master : String = SparkConf ().get("spark.master", " local[*]") ,
38
43
appName : String = "Kotlin Spark Sample ",
39
44
logLevel : SparkLogLevel = ERROR ,
40
45
func : KSparkSession .() -> Unit ,
@@ -58,10 +63,17 @@ inline fun withSpark(
58
63
59
64
}
60
65
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
+ */
61
73
@JvmOverloads
62
74
inline fun withSpark (builder : Builder , logLevel : SparkLogLevel = ERROR , func : KSparkSession .() -> Unit ) {
63
75
builder
64
- .orCreate
76
+ .getOrCreate()
65
77
.apply {
66
78
KSparkSession (this ).apply {
67
79
sparkContext.setLogLevel(logLevel)
0 commit comments