How can I get the current SparkSession in any place of the codes?

前端 未结 3 1546
暗喜
暗喜 2020-12-25 15:11

I have created a session in the main() function, like this:

val sparkSession = SparkSession.builder.master(\"local[*]\").appName(\"Simple Applic         


        
3条回答
  •  执笔经年
    2020-12-25 15:42

    When SparkSession variable has been defined as

    val sparkSession = SparkSession.builder.master("local[*]").appName("Simple Application").getOrCreate()
    

    This variable is going to point/refer to only one SparkSession as its a val. And you can always pass to different classes for them to access as well as

    val newClassCall = new NewClass(sparkSession)
    

    Now you can use the same sparkSession in that new class as well.

提交回复
热议问题