pyspark.sql.Catalog.getTable

Catalog.getTable(tableName: str) → pyspark.sql.catalog.Table

Get the table or view with the specified name. This table can be a temporary view or a table/view. This throws an AnalysisException when no Table can be found.

Parameters
tableNamestr

name of the table to check existence.

Examples

>>> df = spark.sql("CREATE TABLE tab1 (name STRING, age INT) USING parquet")
>>> spark.catalog.getTable("tab1")
Table(name='tab1', catalog='spark_catalog', namespace=['default'], ...
>>> spark.catalog.getTable("default.tab1")
Table(name='tab1', catalog='spark_catalog', namespace=['default'], ...
>>> spark.catalog.getTable("spark_catalog.default.tab1")
Table(name='tab1', catalog='spark_catalog', namespace=['default'], ...
>>> df = spark.sql("DROP TABLE tab1")
>>> spark.catalog.getTable("tab1")
Traceback (most recent call last):
    ...
pyspark.sql.utils.AnalysisException: ...