Repository navigation
Conversation
…stamps Unwrapped google.protobuf.Timestamp fields always became TIMESTAMP(NANOS,true) columns, so consumers limited to microsecond or millisecond resolution (Iceberg v2 clients, for example) could not read them without a schema rewrite. Add parquet.proto.timestampUnit (MILLIS, MICROS, NANOS) so the writer and the schema converter agree on the column's logical type unit. The default stays NANOS, so existing files and callers are unaffected. Values are truncated toward negative infinity rather than rounded, which keeps the stored value a lower bound of the original instant and matches what a reader recovers at that resolution.
|
Friendly ping — this PR is ready for review and CI approval when a maintainer has a moment. |
| * recovers, since the low-order digits are below the column's resolution. | ||
| */ | ||
| static long toTimestampUnit(Timestamp timestamp, TimeUnit unit) { | ||
| long nanos = Timestamps.toNanos(timestamp); |
There was a problem hiding this comment.
For 2500-01-01T00:00:00Z, Timestamps.toNanos calls Math.multiplyExact(16_725_225_600L, 1_000_000_000L) and throws ArithmeticException before we select the unit. Every instant after 2262-04-11T23:47:16.854775807Z exceeds Long.MAX_VALUE in nanoseconds, even though milliseconds and microseconds fit through year 9999. Could the MILLIS and MICROS branches call Timestamps.toMillis and Timestamps.toMicros directly and cover year 2500 in both round-trip tests?
| } | ||
|
|
||
| unwrapProtoWrappers = configuration.getBoolean(PB_UNWRAP_PROTO_WRAPPERS, unwrapProtoWrappers); | ||
| timestampUnit = parseTimestampUnit(configuration.get(PB_TIMESTAMP_UNIT)); |
There was a problem hiding this comment.
The setter says Ignored unless unwrapping is enabled above, but an invalid value still prevents writer initialization. Could both configuration entry points honor the unwrap flag?
| With `parquet.proto.unwrapProtoWrappers` set, wrapper messages such as `google.protobuf.Timestamp`, | ||
| `google.type.Date`, `google.protobuf.*Value` and `google.type.TimeOfDay` are stored as the | ||
| primitive value they carry instead of a nested group, annotated with the matching logical type. | ||
| Unwrapped `Timestamp` columns use microsecond (`parquet.proto.timestampUnit=MICROS`) or | ||
| millisecond (`MILLIS`) resolution when a reader or platform cannot consume nanosecond timestamps, | ||
| for example Iceberg v2 clients. The default stays `NANOS`. Values are truncated toward negative | ||
| infinity to the configured unit, so the stored value never lands after the original instant. |
There was a problem hiding this comment.
| With `parquet.proto.unwrapProtoWrappers` set, wrapper messages such as `google.protobuf.Timestamp`, | |
| `google.type.Date`, `google.protobuf.*Value` and `google.type.TimeOfDay` are stored as the | |
| primitive value they carry instead of a nested group, annotated with the matching logical type. | |
| Unwrapped `Timestamp` columns use microsecond (`parquet.proto.timestampUnit=MICROS`) or | |
| millisecond (`MILLIS`) resolution when a reader or platform cannot consume nanosecond timestamps, | |
| for example Iceberg v2 clients. The default stays `NANOS`. Values are truncated toward negative | |
| infinity to the configured unit, so the stored value never lands after the original instant. | |
| Set `parquet.proto.unwrapProtoWrappers=true` to write supported protobuf message fields as | |
| Parquet primitives. For example, `google.protobuf.BoolValue` becomes a `BOOLEAN` column, | |
| and `google.protobuf.Timestamp` becomes an `INT64` column with a UTC-adjusted `TIMESTAMP` annotation. | |
| For unwrapped `Timestamp` fields, set `parquet.proto.timestampUnit` to `NANOS` (the default), | |
| `MICROS`, or `MILLIS`. The writer rounds each timestamp down to the configured unit. |
|
Fixed in The full protobuf module passes on Java 17: 141 tests, no failures or skips; Spotless and RAT pass. |
Rationale for this change
Unwrapped
google.protobuf.Timestampfields are always written asTIMESTAMP(NANOS,true)columns, which makes them unreadable for consumers capped at microsecond or millisecond resolution — Iceberg v2 clients and Athena among them, since nanosecond timestamp types arrive only in Iceberg v3 (GH-3972).What changes are included in this PR?
Adds the
parquet.proto.timestampUnitsetting, acceptingMILLIS,MICROS(default is stillNANOS):ProtoWriteSupportreads the setting and converts the unwrappedTimestampvalue to that unit's epoch count.ProtoSchemaConverterannotates the column asTIMESTAMP(unit,true)so the footer schema matches the stored values.BadConfigurationExceptionnaming the setting instead of silently producing a mismatched column.parquet-protobuf/README.mddocuments the setting.Values are truncated toward negative infinity rather than rounded, so the stored value stays a lower bound of the original instant and stays monotonic.
Default behavior is unchanged: with the setting absent the column stays
TIMESTAMP(NANOS,true)and the value is the nanosecond count, exactly as before.Are these changes tested?
Yes. New coverage:
ProtoSchemaConverterTest:TIMESTAMP(MICROS,true)/TIMESTAMP(MILLIS,true)schema output, the setting read from aConfiguration, and theNANOSdefault.ProtoWriteSupportTest: micros and millis round trips through a real Parquet file, the exactaddLongvalue written for a millis column, truncation toward negative infinity before the epoch, rejection of an unknown unit, and case-insensitive parsing of the setting.Commands run locally (JDK 17, Maven 3.10):
Are there any user-facing changes?
Yes, additively:
parquet.proto.timestampUnitis a new optional setting. Behavior without it is unchanged.Closes #3972