Skip to main content

setCurrentCatalog

Sets the current default catalog in this session.

Syntax​

setCurrentCatalog(catalogName: str)

Parameters​

Parameter

Type

Description

catalogName

str

Name of the catalog to set.

Parameter

Type

Description

catalogName

str

Name of the catalog to set.

Examples​

Python
spark.catalog.setCurrentCatalog("spark_catalog")

Setting a catalog that doesn't exist raises an AnalysisException with the NO_SUCH_CATALOG_EXCEPTION error condition, and the current catalog doesn't change. To handle a catalog that might not exist, catch the 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