Pular para o conteúdo principal

getOrCreate (SparkSession.Builder)

Obtém um SparkSession existente ou, se não houver um existente, cria um novo com base nas opções definidas neste construtor.

Este método primeiro verifica se há um SparkSession default global válido e, em caso afirmativo, retorna esse. Se não existir um SparkSession default global válido, o método cria um novo SparkSession e o atribui como o default global. Quando um SparkSession existente é retornado, as opções de configuração especificadas neste construtor são aplicadas a ele. Para criar uma nova sessão sem verificação, use create.

Sintaxe

getOrCreate()

Devolve

SparkSession

Exemplos

Python
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