设置此会话中的当前默认目录。
Syntax
setCurrentCatalog(catalogName: str)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
catalogName |
str | 要设置的目录的名称。 |
示例
spark.catalog.setCurrentCatalog("spark_catalog")
设置不存在的目录会触发错误NO_SUCH_CATALOG_EXCEPTION条件的 ,AnalysisException当前目录不会改变。 要处理可能不存在的目录,请捕捉异常:
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