getOrCreate (SparkSession.Builder)

Obtiene una existente SparkSession o, si no existe, crea una nueva basándose en las opciones establecidas en este constructor.

Este método primero comprueba si existe un valor predeterminado SparkSession global válido y, de ser así, lo devuelve. Si no existe un valor predeterminado SparkSession global válido, el método crea uno nuevo SparkSession y lo asigna como el valor predeterminado global. Cuando se devuelve un existente SparkSession , se aplican las opciones de configuración especificadas en este constructor. Para crear una nueva sesión sin comprobar, usa create.

Syntax

getOrCreate()

Devoluciones

SparkSession

Examples

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