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

前端 未结 3 1552
暗喜
暗喜 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:43

    Since 2.2.0 you can access the active SparkSession through:

    /**
     * Returns the active SparkSession for the current thread, returned by the builder.
     *
     * @since 2.2.0
     */
    def getActiveSession: Option[SparkSession] = Option(activeThreadSession.get)
    

    or default SparkSession:

    /**
     * Returns the default SparkSession that is returned by the builder.
     *
     * @since 2.2.0
     */
    def getDefaultSparkSession: Option[SparkSession] = Option(defaultSession.get)
    

提交回复
热议问题