Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Sets the current default catalog in this session.
Syntax
setCurrentCatalog(catalogName: str)
Parameters
| Parameter | Type | Description |
|---|---|---|
catalogName |
str | Name of the catalog to set. |
Examples
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:
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