既存の SparkSession を取得するか、もし存在しなければ、このビルダーで設定されたオプションに基づいて新しいを作成します。
このメソッドはまず有効なグローバルデフォルト SparkSession の有無を確認し、存在する場合はそれを返します。 有効なグローバルデフォルト SparkSession が存在しない場合、メソッドは新しい SparkSession を作成し、それをグローバルデフォルトとして割り当てます。 既存の SparkSession が返されると、このビルダーで指定された設定オプションが適用されます。 チェックせずに新しいセッションを作成するには createを使います。
Syntax
getOrCreate()
Returns
SparkSession
例示
s1 = SparkSession.builder.config("k1", "v1").getOrCreate()
s1.conf.get("k1") == "v1"
# True
# The configuration of the SparkSession can be changed afterwards.
s1.conf.set("k1", "v1_new")
s1.conf.get("k1") == "v1_new"
# True
# When an existing SparkSession is returned, the config options specified
# in this builder are applied to the existing SparkSession.
s2 = SparkSession.builder.config("k2", "v2").getOrCreate()
s1.conf.get("k1") == s2.conf.get("k1") == "v1_new"
# True
s1.conf.get("k2") == s2.conf.get("k2") == "v2"
# True