Skip to content

Spec: clarify Avro encoding for day partition transform in manifests - #16446

Merged
kevinjqliu merged 4 commits into
apache:mainfrom
laskoviymishka:spec-day-transform-encoding
Jun 13, 2026
Merged

kevinjqliu merged 4 commits into
apache:mainfrom
laskoviymishka:spec-day-transform-encoding

Conversation

@laskoviymishka

Copy link
Copy Markdown
Contributor

Documents that writers SHOULD encode day partition fields in Avro manifests with logicalType: date and readers MUST accept both plain int and int with logicalType: date. The logical Iceberg result type remains int.

Resolves the ambiguity between the spec's transform result type table (int) and the de facto behavior of Java, PyIceberg, and Rust (logical date), which has caused real interop failures.

Issue: #16414
Discussion: https://lists.apache.org/thread/qqw5oog5swmswxqqmp693vz1rw132xb6

Documents that writers SHOULD encode `day` partition fields in Avro
manifests with `logicalType: date` and readers MUST accept both plain
`int` and `int` with `logicalType: date`. The logical Iceberg result
type remains `int`.

Resolves the ambiguity between the spec's transform result type table
(`int`) and the de facto behavior of Java, PyIceberg, and Rust (logical
`date`), which has caused real interop failures.

Issue: apache#16414
Discussion: https://lists.apache.org/thread/qqw5oog5swmswxqqmp693vz1rw132xb6
@laskoviymishka

Copy link
Copy Markdown
Contributor Author

To connect with past generation of this - #10616

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up @laskoviymishka 🙌

Comment thread format/spec.md Outdated
| **`year`** | Extract a date or timestamp year, as years from 1970 | `date`, `timestamp`, `timestamptz`, `timestamp_ns`, `timestamptz_ns` | `int` |
| **`month`** | Extract a date or timestamp month, as months from 1970-01-01 | `date`, `timestamp`, `timestamptz`, `timestamp_ns`, `timestamptz_ns` | `int` |
| **`day`** | Extract a date or timestamp day, as days from 1970-01-01 | `date`, `timestamp`, `timestamptz`, `timestamp_ns`, `timestamptz_ns` | `int` |
| **`day`** | Extract a date or timestamp day, as days from 1970-01-01 | `date`, `timestamp`, `timestamptz`, `timestamp_ns`, `timestamptz_ns` | `int` [1] |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| **`day`** | Extract a date or timestamp day, as days from 1970-01-01 | `date`, `timestamp`, `timestamptz`, `timestamp_ns`, `timestamptz_ns` | `int` [1] |
| **`day`** | Extract a date or timestamp day, as days from 1970-01-01 | `date`, `timestamp`, `timestamptz`, `timestamp_ns`, `timestamptz_ns` | `date` |

I think having the int conflicts with the Avro types table below: https://github.com/apache/iceberg/blob/main/format/spec.md#avro

If we decide to keep the partition Tuple in V4, then we would also add the date logical type annotation in Parquet: https://github.com/apache/iceberg/blob/main/format/spec.md#parquet I think this would be the most consistent.

This would effectively revert it back to date which it was before: #10616 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would still keep annotation here, this note bring quite some usefull context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: applied your suggestion, the row now reads `date` and the note has been simplified

Per community feedback on the dev list and PR review:
- Fokko Driesprong: prefers reverting the result type to `date` for
  consistency with the Avro types table (PR review r3283810222).
- Kevin Liu: supports changing the spec back to `date` to match
  default behavior in Java, PyIceberg, and Rust.
- Ryan Blue: notes the Avro spec already requires readers to ignore
  unrecognized logical type annotations, so reader tolerance for the
  historical plain-`int` form is inherited from Avro.

The footnote is preserved with rewritten text capturing the historical
context, so future readers don't re-litigate this every cycle.
@laskoviymishka
laskoviymishka marked this pull request as ready for review May 21, 2026 20:54
Comment thread format/spec.md Outdated

Notes:

1. The result type for `day` has been documented as both `int` and `date` in earlier revisions of this spec. The physical representation has always been a 4-byte integer counting days from `1970-01-01`, regardless of whether the Avro field is annotated with `logicalType: date`. Readers may encounter manifests in either form; per the Avro specification, unrecognized logical type annotations are ignored, so the bytes on disk are identical.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per the Avro specification, unrecognized logical type annotations are ignored, so the bytes on disk are identical.

Small nit, but I don't think this really captures the problem with the different types? I think all Iceberg compatible readers by definition must recognize logicalType: date. IIUC the issue is that iceberg hasn't defined the promotion in either direction between int and date. If we are deferring to the Avro specification type resolution might be the more applicable section (since it doesn't seem to consider logical types, I'm not clear if this is intentional, an oversight. One could construe this about only talking about physical type or that the types are not equal, and we are defining here an type-promotion or reconciliation specific to iceberg.).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can just simplify and not refer to the Avro specification at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, agreed.

Dropped the Avro-spec reference in the latest revision. The note now just states the physical representation and the writer/reader contract directly, without leaning on "Avro ignores unknown annotations" framing.

Re your deeper point on Iceberg not having defined int ↔ date promotion: I think that's a separate spec gap worth its own issue rather than expanding this PR. Happy to open one as a follow-up if you agree it's worth tracking.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int to date promotion would be a real spec change. I think this more focused change makes sense. I'm not actually sure int to date promotion is something we want to add generally.

Comment thread format/spec.md Resolved
Comment thread format/spec.md Outdated

Notes:

1. The result type for `day` has been documented as both `int` and `date` in earlier revisions of this spec. The physical representation has always been a 4-byte integer counting days from `1970-01-01`, regardless of whether the Avro field is annotated with `logicalType: date`. Readers may encounter manifests in either form; per the Avro specification, unrecognized logical type annotations are ignored, so the bytes on disk are identical.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with the conclusion "so the bytes on disk are identical". That's true, but not a result of the Avro spec's requirement. How about "Writers have produced fields with the logicalType: date annotation because Avro requires that readers must ignore unknown logical types. The bytes on disk are identical so readers must accept both forms and can choose how to pass on the data."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this wording

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we break this down into just two sentences? I'd rather we try to avoid keeping the decision making out of the spec imho

The physical representation is a 4-byte integer counting days from `1970-01-01. Writers may produce Avro fields annotated both with and without a logical 'date' annotation and readers must accept both forms.

I'm fine with everything as is as well I just think we don't need to include the history here.

@laskoviymishka laskoviymishka May 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with @RussellSpitzer's shorter variant below since it's a subset of @rdblue's covers bytes-identical + writer/reader contract without the Avro-spec rationale that @emkornfield pushed back on.

Let me know if you'd prefer the longer form with the "writers have produced... because Avro requires..." framing; happy to swap.

Adopts @RussellSpitzer's two-sentence wording and applies @rdblue's
preference to place the Notes block at the end of the section rather
than between two paragraphs. Drops the Avro-specification reference
per @emkornfield's concern that it doesn't capture the actual issue
(Iceberg readers must recognize logicalType: date by definition).

The note now states the physical representation and the writer/reader
contract directly, without commentary or historical framing.
@laskoviymishka

Copy link
Copy Markdown
Contributor Author

Updated:

  • Row: `int` → `date` (per @Fokko's suggestion)
  • Note: simplified to two sentences per @RussellSpitzer (drops the Avro-spec reference per @emkornfield's pushback, drops the historical framing)
  • Notes block moved to end of section per @rdblue

@Fokko @kevinjqliu @rdblue @emkornfield @amogh-jahagirdar @RussellSpitzer -- would appreciate another look when you have a moment.

Comment thread format/spec.md Outdated

Notes:

1. The physical representation is a 4-byte integer counting days from `1970-01-01`. Writers may produce Avro fields annotated both with and without a logical `date` annotation, and readers must accept both forms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. The physical representation is a 4-byte integer counting days from `1970-01-01`. Writers may produce Avro fields annotated both with and without a logical `date` annotation, and readers must accept both forms.
1. Readers must also accept `int` values for the `day` transform, interpreting each integer as a date represented by the number of days since `1970-01-01`.

nit: could we keep this "Partition Transforms" section from mentioning file format specifics?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And move the Avro specific wording to https://iceberg.apache.org/spec/#avro
something like

#### Manifest Partition Field Encoding

Manifest files store partition values in the `partition` tuple.

For partition fields produced by the `day` transform, the Avro field may be
encoded either as `"int"` or as `{ "type": "int", "logicalType": "date" }`.

Readers must accept both forms. Writers should encode `day` partition fields as
`{ "type": "int", "logicalType": "date" }`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this covered by the Avro spec as @rdblue already mentioned:

Language implementations may choose to represent logical types with an appropriate native type, although this is not required.

I think we should avoid adding notes unless strickly required to aid readability of the spec.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then maybe we dont need the avro section.

Readers must also accept int values for the day transform

These are Iceberg types, which maps to avro int and avro date respectively. So its implied that avro reader should read both and avro writer should write date

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. The physical representation is a 4-byte integer counting days from `1970-01-01`. Writers may produce Avro fields annotated both with and without a logical `date` annotation, and readers must accept both forms.
1. Readers must also accept `int` values for the `day` transform, interpreting each integer as a `date` represented by the number of days since `1970-01-01`.

How about this? I think this keeps the note format-neutral and avoids over-explaining Avro mapping. Since this is in the Partition Transforms section, the referenced types are implied to be Iceberg types.

@kevinjqliu kevinjqliu left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its best to keep Avro specifics out of the Partition Transform section. We can just mention that readers must accept Iceberg int and Iceberg date and let the Avro mapping section handle the rest.

Thoughts?

Comment thread format/spec.md Outdated

Notes:

1. The physical representation is a 4-byte integer counting days from `1970-01-01`. Writers may produce Avro fields annotated both with and without a logical `date` annotation, and readers must accept both forms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. The physical representation is a 4-byte integer counting days from `1970-01-01`. Writers may produce Avro fields annotated both with and without a logical `date` annotation, and readers must accept both forms.
1. Readers must also accept `int` values for the `day` transform, interpreting each integer as a `date` represented by the number of days since `1970-01-01`.

How about this? I think this keeps the note format-neutral and avoids over-explaining Avro mapping. Since this is in the Partition Transforms section, the referenced types are implied to be Iceberg types.

Drop the Avro-specific framing from the partition transform note so the
Partition Transforms section stays format-neutral. The note now states
the reader contract in terms of Iceberg types; Avro mapping is handled
by the Avro types table in Appendix A.

Co-authored-by: Isaac
@rdblue

rdblue commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

I like where this ended up. It's direct and clear. Thanks, @laskoviymishka!

@kevinjqliu kevinjqliu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

🚢 it

@kevinjqliu
kevinjqliu merged commit 40a532b into apache:main Jun 13, 2026
18 checks passed
@kevinjqliu

Copy link
Copy Markdown
Contributor

Thanks @laskoviymishka for the PR and everyone for the reviews

tanmayrauth added a commit to tanmayrauth/iceberg-go that referenced this pull request Jun 17, 2026
Cite the day-transform date result type and plain-int reader requirement
from apache/iceberg#16446 in the applyDayTransformDates godoc and test
rationale. Document why the atype.Date return v fallthrough is unreachable
so it is not 'fixed' in a way that reintroduces apache#1200.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Specification Issues that may introduce spec changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.