Jump to content

Partition

From Open Lakehouse Wiki
Partition
Field Data engineering
Key parts Spark partitions, table partitions (Hive-style, Iceberg, Delta Lake), Kafka topic partitions
Open source implementations Apache Spark, Apache Iceberg, Delta Lake, Apache Kafka
Related Shuffle, Executor, Predicate pushdown, Small files problem
Last verified 22 November 2026 against the v4.3.0 tag of apache/spark (docs and PySpark source), a run on a Spark 4.3.1-SNAPSHOT build, the Apache Iceberg 1.12.0 spec and partitioning docs, the Delta Lake protocol at v4.4.1 and the clustering docs, and the Apache Kafka 4.4 introduction.

A partition is a subset of a dataset that a system stores or processes as one unit. In a lakehouse the word has several distinct meanings, depending on whether it refers to how an engine splits work, how a table lays out files, or how a message log splits a topic. An Apache Spark partition is a slice of data processed by one task. A table partition in Hive, Apache Iceberg or Delta Lake is a group of files that share partition values. An Apache Kafka partition is an ordered log inside a topic. These meanings interact (a Spark job reads table partitions into Spark partitions, and a Kafka source maps topic partitions to Spark partitions), but they are not the same thing.

Spark in-memory partition

Main article: Apache Spark

In Spark, a partition is a piece of an RDD or DataFrame, and Spark runs one task for each partition.[1] The number of partitions therefore sets how much parallel work a stage can do on the cluster's executors. When Spark reads files, it packs at most spark.sql.files.maxPartitionBytes (default 128 MB) into one partition; after a join or aggregation, it uses spark.sql.shuffle.partitions (default 200) partitions, which adaptive query execution can coalesce at runtime.[2]

Two DataFrame methods change the number of partitions. repartition hash-partitions the data and always causes a shuffle.[3][1] coalesce only reduces the number of partitions and creates a narrow dependency without a shuffle: going from 1,000 partitions to 100, each new partition claims 10 old ones.[4]

from pyspark.sql import functions as F

df = spark.range(0, 1_000_000)
wide = df.repartition(8, "id")   # shuffle into 8 hash partitions
narrow = wide.coalesce(2)        # merge into 2 partitions, no new shuffle

narrow.select(F.spark_partition_id()).distinct().count()   # 2

A Spark partition exists only while a job runs. It is not stored, and it is unrelated to the directory layout of the table being read, except that file and partition layout influence how Spark splits its input.

Hive-style table partitioning

Hive-style partitioning stores a table's files in directories named after partition column values, such as gender=male/country=US/. The partition values are encoded in the path of each directory. Spark's built-in file sources discover this layout automatically and add the partition columns to the schema.[5]

Queries skip directories only when they filter on the partition column itself. In Hive, a table partitioned by event_date has an explicit event_date column, and a query without an event_date filter scans every file, even when it filters on the timestamp that the date was derived from.[6] Very fine partitioning also produces many small files; see small files problem.

Apache Iceberg hidden partitioning and partition evolution

Main article: Apache Iceberg

Iceberg uses hidden partitioning. A partition spec derives partition values from table columns through transforms such as identity, bucket[N], truncate[W], year, month, day and hour. Because the table records the transform, Iceberg turns a filter on the source column into a partition filter, and users do not have to add partition predicates to their queries.[7][6] Partition values are stored in manifests for each data file, not taken from directory names.[7]

Iceberg also supports partition evolution: a table's partitioning can change by adding, removing, renaming or reordering partition fields. Each change creates a new partition spec, and files written under an older spec keep it; at scan time, Iceberg converts filters using the spec each manifest was written with.[7]

Delta Lake partitioning and liquid clustering

Main article: Delta Lake

A Delta Lake table can have partition columns, recorded in the table metadata. The transaction log stores each file's partition values, and readers must take the values from the log. The reference implementation writes files into Hive-style column=value directories, but the protocol says this layout only follows convention and is not required.[8]

Liquid clustering is Delta Lake's alternative to partitioning and ZORDER. A table declares clustering columns with CLUSTER BY, OPTIMIZE clusters the data incrementally, and the clustering columns can be changed later with ALTER TABLE without rewriting existing data. Clustering cannot be combined with partitioning or ZORDER on the same table. It is available from Delta Lake 3.1.0, and the preview flag was removed in 3.2.[9] The protocol requires writers of clustered tables to record per-file statistics for the clustering columns, which readers use for data skipping.[8]

Apache Kafka topic partitions

A Kafka topic is split into partitions spread over brokers. Events with the same key go to the same partition, consumers read each partition in the order its events were written, and replication works per partition.[10] Ordering is guaranteed within a partition, not across a topic.

When Structured Streaming reads from Kafka, Spark by default maps each Kafka topic partition to one Spark partition. The minPartitions option asks Spark to split large Kafka partitions into more Spark partitions.[11]

Which partition am I looking at?

Meaning Where it lives Lifetime Who decides it Changed by
Spark partition Memory and local disk of executors One job or stage Spark (file split size, shuffle partitions, AQE) or the user repartition, coalesce, SQL hints[2]
Hive-style table partition Directory names in storage (col=value/) Permanent, part of the table Table author (partition columns) Writing the data into a new directory layout
Iceberg partition Partition tuples in manifests, derived by transforms Permanent, per partition spec Table author (partition spec) Partition evolution; old files keep their spec[7]
Delta Lake partition or cluster Partition values or statistics in the transaction log Permanent Table author (PARTITIONED BY or CLUSTER BY) Clustering columns via ALTER TABLE[9]
Kafka topic partition Brokers Lifetime of the topic Topic configuration; the event key decides which partition an event goes to[10] Kafka topic administration

See also

References

  1. ↑ 1.0 1.1 RDD Programming Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  2. ↑ 2.0 2.1 Performance Tuning (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  3. ↑ pyspark.sql.DataFrame.repartition (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  4. ↑ pyspark.sql.DataFrame.coalesce (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  5. ↑ Parquet Files: Partition Discovery (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  6. ↑ 6.0 6.1 Partitioning (Apache Iceberg 1.12.0). Apache Software Foundation.Retrieved 2026-11-22.
  7. ↑ 7.0 7.1 7.2 7.3 Iceberg Table Spec (apache-iceberg-1.12.0). Apache Software Foundation.Retrieved 2026-11-22.
  8. ↑ 8.0 8.1 Delta Transaction Log Protocol (v4.4.1). Delta Lake.Retrieved 2026-11-22.
  9. ↑ 9.0 9.1 Use liquid clustering for Delta tables. Delta Lake.Retrieved 2026-11-22.
  10. ↑ 10.0 10.1 Introduction (Apache Kafka 4.4). Apache Software Foundation.Retrieved 2026-11-22.
  11. ↑ Structured Streaming + Kafka Integration Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.