Aller au contenu principal

setCurrentCatalog

Définit le catalogue default actuel dans cette session.

Syntaxe​

setCurrentCatalog(catalogName: str)

parameter​

parameter

Type

Description

catalogName

str

Nom du catalogue à définir.

parameter

Type

Description

catalogName

str

Nom du catalogue à définir.

Exemples​

Python
spark.catalog.setCurrentCatalog("spark_catalog")

La définition d'un catalogue qui n'existe pas déclenche une exception AnalysisException avec la condition d'erreur NO_SUCH_CATALOG_EXCEPTION, et le catalogue actuel ne change pas. Pour gérer un catalogue qui pourrait ne pas exister, attrapez l'exception :

Python
from pyspark.errors import AnalysisException

catalog_name = "my_catalog"

try:
spark.catalog.setCurrentCatalog(catalog_name)
except AnalysisException as e:
if e.getCondition() == "NO_SUCH_CATALOG_EXCEPTION":
print(f"Catalog '{catalog_name}' doesn't exist. The current catalog is still '{spark.catalog.currentCatalog()}'.")
else:
raise