1919 */  
2020package  org.jetbrains.kotlinx.spark.api 
2121
22+ import  org.apache.spark.SparkConf 
2223import  org.apache.spark.sql.SparkSession.Builder 
2324import  org.apache.spark.sql.UDFRegistration 
2425import  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
3540inline  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
6274inline  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