≈ The Lake

Part 5 · Apache Iceberg spec · Chapter 18

Hidden partitioning and partition evolution

Partition transforms (identity, bucket, truncate, year, month, day, hour, void), why partition values live in manifests and not in paths, how a filter on a source column is projected to partition predicates, and how specs evolve without rewriting data.

complete ~40 min

After this chapter you should be able to:
  • Compute bucket, truncate and time transforms exactly as the spec defines them, including the Murmur3 hash.
  • Derive the inclusive and strict projections of a predicate through each transform.
  • Explain partition field ids, spec ids and how a spec evolves in v1 and v2.
  • Plan a scan over files written with several specs.

In a Hive table, the partition is a column. Users write WHERE event_date = '2026-11-03' next to WHERE ts > …, and a query that forgets the partition column scans everything. In Iceberg the partition is a function of columns. The table’s partition spec says ts_day = day(ts), writers compute it, and readers derive partition filters from ordinary filters on ts. Users never see ts_day, which is why Iceberg calls this hidden partitioning. Because queries don’t name partitions, the partitioning can change without breaking them.

Links point to apache/iceberg at 9d2bf51.

Partition values are derived, not stored

A partition spec is a list of fields. Each field has a source column id, a partition field id, a transform and a name.[spec] In JSON:

{ "spec-id": 0,
  "fields": [ { "source-id": 4, "field-id": 1000, "name": "ts_day",    "transform": "day" },
              { "source-id": 1, "field-id": 1001, "name": "id_bucket", "transform": "bucket[16]" } ] }

Three rules from the spec shape everything else:

  • “Partition values for a data file must be the same for all records stored in the data file.” Writers group rows by partition tuple before writing.
  • Partition specs are used “to transform predicates to partition predicates, in addition to transforming data values.” The spec’s own summary: “the partitioning can change and the correct partition filters are always derived from column predicates.”
  • “Partition field IDs must be reused if an existing partition spec contains an equivalent field.”

The partition tuple is stored in each manifest entry, and that is the only place a reader gets it from. The default location provider still writes a readable path such as data/ts_day=2026-11-03/00000-….parquet, built by PartitionSpec.partitionToPath, but only people read it.[src] With write.object-storage.enabled the provider adds a hash prefix to spread keys across S3 prefixes, and write.object-storage.partitioned-paths=false drops the partition path altogether. Reads are unaffected either way.[src]

Hidden partitioning: one write, one read
WriterINSERT INTO eventsMetadataspecs, manifestsData files.parquetReaderWHERE ts > '…03T06:00'1. default spec: ts_day = day(ts)2. tuple = (day(row.ts))3. PUT data/ts_day=2026-11-03/….parquet4. manifest entry: partition {1000: 20760}5. specs by id; manifests with their spec id6. inclusive projection per spec7. prune manifests, then entries8. read with residual
  1. default spec: ts_day = day(ts). The writer reads the default partition spec from table metadata. The user never names ts_day in an INSERT. Partitioning ↗
  2. tuple = (day(row.ts)). Each row's partition tuple is computed with the spec's transforms. All rows in one data file must share a tuple, so writers group rows by it. Partition Transforms ↗
  3. PUT data/ts_day=2026-11-03/….parquet. The default location provider puts a human-readable partition path in the file name. Nothing reads it back: the path is for people and for object-store key spreading. LocationProviders ↗
  4. manifest entry: partition {1000: 20760}. The partition tuple is stored in the manifest entry, keyed by partition field id, and the manifest list records the manifest's spec id. This is the only place readers get partition values from.
  5. specs by id; manifests with their spec id. A table can hold files written with several specs. Each manifest (v1 to v3) holds files of one spec. ManifestGroup ↗
  6. inclusive projection per spec. ts > X becomes ts_day >= day(X) for a day spec and ts_hour >= hour(X + 1µs) for an hour spec. A spec with no field on ts projects to true. Projections ↗
  7. prune manifests, then entries. The projected filter is tested against manifest partition summaries and then each entry's tuple, as in chapter 16. Scan Planning ↗
  8. read with residual. The strict projection tells whether every row of a file matches. If it does, the residual is true; otherwise the original filter runs on rows.
Follows the spec's Partitioning and Scan Planning sections and Projections, ManifestGroup and LocationProviders at 9d2bf51.
Quiz Derived partitionsAnswers are scheduled for spaced review on the Review page.

Q1. A table is partitioned by days(ts). A user writes WHERE ts > '2026-11-03T06:00' and never mentions the partition. Can planning still prune by partition?

How sure are you?

Q2. Where does an Iceberg reader get a data file's partition values?

How sure are you?

Q3. What must be true of the rows in one data file?

How sure are you?

Transforms

TransformResultSource types (subset)
identitythe valuealmost any primitive
bucket[N]int in [0, N)int, long, decimal, date, time, timestamps, string, uuid, fixed, binary
truncate[W]same typeint, long, decimal, string, binary
year, monthint: years or months from 1970date, timestamps
daydate (days from 1970-01-01)date, timestamps
hourint: hours from 1970-01-01 00:00timestamps
voidalways nullany

“All transforms must return null for a null input value.”[spec] A reader that meets a transform it doesn’t know ignores that field when filtering; a writer must not commit with one.[spec]

Bucket: Murmur3

“The 32-bit hash implementation is the 32-bit Murmur3 hash, x86 variant, seeded with 0”, and the bucket is the hash with its sign bit cleared, mod N:[spec]

def bucket_N(x) = (murmur3_x86_32_hash(x) & Integer.MAX_VALUE) % N

Java computes it with Guava’s murmur3_32_fixed.[src][src] What gets hashed depends on the type (Appendix B):[spec]

TypeBytes hashedTest value
int, long8 little-endian bytes of the value as a long34 → 2017239379
datedays from epoch, hashed like an int2017-11-16 → -653330422
timestampmicroseconds from epoch as a long2017-11-16T22:31:08 → -2047944441
stringUTF-8 bytesiceberg → 1210000089

Ints are hashed as longs on purpose: “Integer and long hash results must be identical for all integer values. This ensures that schema evolution does not change bucket partition values if integer types are promoted.” Floats are hashed as doubles for the same reason. Nanosecond timestamps are converted to microseconds first, so timestamp_ns and timestamp values hash the same.

bucket[N] spreads values evenly, which suits high-cardinality keys used in equality filters and joins. It cannot prune a range: hashing destroys order.

Quiz BucketAnswers are scheduled for spaced review on the Review page.

Q1. How does bucket[N] turn a 32-bit hash into a bucket number?

How sure are you?

Q2. Why are int values hashed as 8-byte longs (hashLong(long(v)))?

How sure are you?

Truncate and time transforms

truncate[W] on integers is v - (v % W) with a non-negative remainder, so truncate[10](-1) = -10. The spec gives the portable form, v - (((v % W) + W) % W), for languages whose % can be negative. Strings truncate to at most L code points and stay valid UTF-8; binary truncates to L bytes; decimals apply W in the column’s scale (W=50, scale 2: 10.65 → 10.50).[spec]

The time transforms count whole units since the epoch, floored. DateTimeUtil.convertMicros handles negative values separately so that 1969-12-31T10:00 is day -1, not 0:[src]

if (micros >= 0) {
  ... return (int) granularity.between(EPOCH, toOffsetDateTime(epochSecond, nanoAdjustment));
} else {
  // add 1 micro ... because the result will always be decremented.
  long nanoAdjustment = Math.floorMod(micros + 1, MICROS_PER_SECOND) * 1000;
  return (int) granularity.between(EPOCH, toOffsetDateTime(epochSecond, nanoAdjustment)) - 1;
}

That was not always so. “A bug in 0.10.0 and earlier caused negative values to be incorrectly transformed by date and timestamp transforms to 1 larger than the correct value.” Files written then are still readable, so the projection code widens any bound below zero by one. For example = -1 projects to IN (-1, 0).[src]

Quiz Truncate and timeAnswers are scheduled for spaced review on the Review page.

Q1. What is truncate[10] of the int -1?

How sure are you?

Q2. truncate[L] on a string keeps what?

How sure are you?

Q3. What is day(1969-12-31T10:00:00) as an integer?

How sure are you?

Projecting a filter

The spec defines the projection planning needs: “if a scan predicate matches a row, then the partition predicate must match that row’s partition.” This is the inclusive projection. Its opposite, the strict projection, “creates a partition predicate that will match a file if all of the rows in the file must match the scan predicate”, and is used for residuals.[spec]

Each transform implements project and projectStrict per operator. For ordered transforms (truncate and the time transforms) the rules are in ProjectionUtil. Inclusive first, then strict:[src]

Row predicateInclusiveStrict
x < vp <= t(v - 1)p < t(v)
x <= vp <= t(v)p < t(v + 1)
x > vp >= t(v + 1)p > t(v)
x >= vp >= t(v)p > t(v - 1)
x = vp = t(v)none (false)
x != vnone (true)p != t(v)

The ±1 turns an open bound into a closed one before transforming. With hours(ts), ts > 2026-11-03T06:00:00 becomes ts_hour >= hour(06:00:00.000001), which is hour 06. The strict form is ts_hour > 06: only hours after 06 are entirely inside the filter.[src]

bucket is unordered. Its inclusive projection handles only = and IN; its strict projection only != and NOT IN. A range on a bucketed column projects to true and prunes nothing.[src] String truncate[W] has a special case for STARTS WITH: a prefix shorter than W stays STARTS WITH, a prefix of exactly W becomes =, and a longer one is truncated.[src]

Projections combines per-field results. For inclusive projection, a predicate on a column with several partition fields is the AND of their projections, and a column with no partition field projects to true. For strict projection it is the OR, and no field gives false.[src]

Quiz ProjectionAnswers are scheduled for spaced review on the Review page.

Q1. A table is partitioned by bucket[16](id). What is the inclusive projection of id < 5?

How sure are you?

Q2. Partitioned by hours(ts). What is the inclusive projection of ts > 2026-11-03T06:00:00?

How sure are you?

Q3. What does the strict projection of a filter guarantee?

How sure are you?

Q4. A spec has both bucket[7](d) and bucket[5](d). How are the two inclusive projections of d = X combined?

How sure are you?

Partition evolution

“Table partitioning can be evolved by adding, removing, renaming, or reordering partition spec fields.” Each change creates a spec with a new spec id. The new spec is added to the table’s list of specs and may become the default. “Changes should not cause partition field IDs to change because the partition field IDs are used as the partition tuple field IDs in manifest files.”[spec]

Nothing is rewritten. Files written under spec 0 keep spec 0’s tuples. Their manifests record spec id 0. New writes use the default spec. In Spark, with Iceberg’s SQL extensions:[grammar]

ALTER TABLE db.events ADD PARTITION FIELD bucket(16, id);
ALTER TABLE db.events REPLACE PARTITION FIELD ts_day WITH hours(ts);
ALTER TABLE db.events DROP PARTITION FIELD id_bucket_16;

BaseUpdatePartitionSpec implements the API. Field ids come from last-partition-id and start at 1000.[src] In v2, adding a field first searches every historical spec for one with the same source and transform (and the same name, if one was given), and reuses its id:[src]

if (formatVersion >= 2 && base != null) {
  for (PartitionField field : allHistoricalFields)
    if (field.sourceId() == sourceId && field.transform().equals(transform))
      if (name == null || field.name().equals(name)) return field;
}
return new PartitionField(sourceId, assignFieldId(), name, transform);

Version 1 did not track field ids. The reference implementation numbered them by position from 1000, so dropping a field would renumber the ones after it. In v1, apply() therefore keeps a dropped field in place with the void transform, which always produces null. The spec recommends the same for v1: never reorder, never drop (use void), add only at the end.[src] Default names come from PartitionNameGenerator: id_bucket_16, category_trunc_3, ts_day, ts_hour.[src]

A spec update is a metadata-only commit. commit() builds the new metadata and calls ops.commit(base, update) once, so a concurrent writer that loses its swap simply retries on top of the new spec (chapter 17).

Quiz EvolutionAnswers are scheduled for spaced review on the Review page.

Q1. A table moves from days(ts) to hours(ts). What happens to files written before the change?

How sure are you?

Q2. In a v2 table, days(ts) (field id 1000) is dropped and later added back. Which field id does it get?

How sure are you?

Q3. How is a partition field dropped in a v1 table?

How sure are you?

Planning across specs

After an evolution, a snapshot holds manifests from several specs. In v1 to v3, each manifest holds files of a single spec, and the manifest list records its partition_spec_id. The spec says filter conversion “uses the partition spec that was used to write the manifest file regardless of the current partition spec.”[spec] ManifestGroup keeps one ManifestEvaluator per spec id, built from Projections.inclusive(spec).project(filter):[src]

LoadingCache<Integer, ManifestEvaluator> evalCache = Caffeine.newBuilder().build(specId -> {
    PartitionSpec spec = specsById.get(specId);
    return ManifestEvaluator.forPartitionFilter(
        Expressions.and(partitionFilter, Projections.inclusive(spec, caseSensitive).project(dataFilter)),
        spec, caseSensitive);
});
... manifest -> evalCache.get(manifest.partitionSpecId()).eval(manifest)

So after a switch from days(ts) to hours(ts), ts > 06:00 prunes old files by day and new files by hour. A query never says which. The v4 draft relaxes the one-spec-per-manifest rule: “Starting in v4, manifests may store files from any spec.”[spec]

One predicate, two partition specs
  1. Filter the source column The query asks for events after 06:00 on the same day.
Older manifests · days(ts)
  1. Keep the whole day The day partition can contain rows on both sides of 06:00.
Newer manifests · hours(ts)
  1. Keep hour 06 onward Earlier hour partitions cannot match.
The reader projects the predicate using each manifest’s spec. Any remaining row filter still applies within the selected files.[Iceberg spec]
Quiz Mixed specsAnswers are scheduled for spaced review on the Review page.

Q1. A scan covers manifests written with spec 0 (day) and spec 1 (hour). Which projection filters each manifest?

How sure are you?

Try it

The lab runs src/sim/iceberg/partition.ts. The table has columns id (long), category (string), ts (timestamp) and event_date (date). It starts as a v2 table partitioned by days(ts), with two appends.

  1. Transform calculator. Type a transform (bucket[16], truncate[3], hour, …) and a value. For bucket it shows the signed hash, the masked hash and the bucket. Try the Appendix B values: id = 34, category = iceberg, event_date = 2017-11-16.
  2. Filter and plan. Each spec’s inclusive and strict projection is shown, and each file is tested with its own spec’s projection.
  3. Evolve. Add hour on ts, drop ts_day, append rows, and watch the same filter prune old and new files differently. Drop ts_hour and add day again to see field id 1000 recycled.

1. Transform calculator

bucket[16](34) = 3 murmur3_x86_32 = 2017239379; & Integer.MAX_VALUE = 2017239379; then % N

Transforms: identity, bucket[N], truncate[W], year, month, day, hour, void. spec ↗ · hash test values ↗

2. Filter and plan, across every spec

WHERE
  • spec 0 (default): 1000: ts_day = day(ts)
    inclusive: ts_day >= 20760 (2026-11-03) · strict: ts_day > 20760 (2026-11-03)

Scans 2 of 5 files; 4 rows match the filter. Each file is tested with the projection of the spec it was written with. ManifestGroup ↗

  • spec 0 ts_day=2026-11-03/00003.parquet → scan with residual (2/3 rows match)
  • spec 0 ts_day=2026-11-04/00004.parquet → scan, every row matches (residual true)

3. Evolve the spec

ADD PARTITION FIELD
DROP PARTITION FIELD
  1. CREATE TABLE … PARTITIONED BY (days(ts)); two appends.

Format v2 · last-partition-id 1000. recycleOrCreatePartitionField ↗ · time projection fixes ↗

Comparison with Delta

Delta partitions by column values. The names are in metaData.partitionColumns, and each add action carries partitionValues, a map from column name to a serialized string.[protocol] There are no transforms in the protocol. A derived partition such as a date from a timestamp is an ordinary column, which a generated column can fill: the column’s metadata holds delta.generationExpression, and writers must enforce it.[protocol] Because every file’s partition values are keyed by the current partition columns, changing them means new metadata and rewriting the data. Delta’s newer answer to the same problem is liquid clustering (chapter 27), which drops directory-style partitions altogether.

Quiz DeltaAnswers are scheduled for spaced review on the Review page.

Q1. Which statements about Delta partitioning are true at the pinned protocol? (select all that apply)

How sure are you?

Concepts in this chapter

Explained here

See how the book's concepts connect →

Primary sources

Review this chapter

This chapter has 17 quiz questions.

Review this chapter's cards → Review all due cards