Repository navigation
Spec: clarify Avro encoding for day partition transform in manifests - #16446
Conversation
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
|
To connect with past generation of this - #10616 |
Fokko
left a comment
There was a problem hiding this comment.
Thanks for picking this up @laskoviymishka 🙌
| | **`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] | |
There was a problem hiding this comment.
| | **`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)
There was a problem hiding this comment.
i would still keep annotation here, this note bring quite some usefull context.
There was a problem hiding this comment.
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.
|
|
||
| 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. |
There was a problem hiding this comment.
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.).
There was a problem hiding this comment.
Or we can just simplify and not refer to the Avro specification at all.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| 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. |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
+1 to this wording
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Updated:
@Fokko @kevinjqliu @rdblue @emkornfield @amogh-jahagirdar @RussellSpitzer -- would appreciate another look when you have a moment. |
|
|
||
| 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. |
There was a problem hiding this comment.
| 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?
There was a problem hiding this comment.
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" }`.
There was a problem hiding this comment.
There was a problem hiding this comment.
then maybe we dont need the avro section.
Readers must also accept
intvalues for thedaytransform
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
There was a problem hiding this comment.
| 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.
|
|
||
| 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. |
There was a problem hiding this comment.
| 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
|
I like where this ended up. It's direct and clear. Thanks, @laskoviymishka! |
|
Thanks @laskoviymishka for the PR and everyone for the reviews |
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.
Documents that writers SHOULD encode
daypartition fields in Avro manifests withlogicalType: dateand readers MUST accept both plainintandintwithlogicalType: date. The logical Iceberg result type remainsint.Resolves the ambiguity between the spec's transform result type table (
int) and the de facto behavior of Java, PyIceberg, and Rust (logicaldate), which has caused real interop failures.Issue: #16414
Discussion: https://lists.apache.org/thread/qqw5oog5swmswxqqmp693vz1rw132xb6