pyspark.sql.Catalog.listPartitions#

Catalog.listPartitions(tableName)[source]#

Lists partition value strings for a table (same as SHOW PARTITIONS).

New in version 4.2.0.

Parameters
tableNamestr

Name of the partitioned table. May be qualified with catalog and database (namespace).

Returns
list

A list of CatalogTablePartition (each partition field is a spec string).

Examples

>>> _ = spark.sql("DROP TABLE IF EXISTS tbl_part_doc")
>>> _ = spark.sql(
...     "CREATE TABLE tbl_part_doc (id INT, p INT) USING parquet PARTITIONED BY (p)"
... )
>>> _ = spark.sql("INSERT INTO tbl_part_doc PARTITION (p = 1) SELECT 1")
>>> parts = [x.partition for x in spark.catalog.listPartitions("tbl_part_doc")]
>>> any("p=1" in s for s in parts)
True
>>> _ = spark.sql("DROP TABLE tbl_part_doc")