Skip to content

GH-3972: Add configurable precision for unwrapped protobuf Timestamps - #3982

Open
Goldloli wants to merge 1 commit into
apache:masterfrom
Goldloli:parquet-proto-unwrapped-timestamp-unit
Open

Goldloli wants to merge 1 commit into
apache:masterfrom
Goldloli:parquet-proto-unwrapped-timestamp-unit

Conversation

@Goldloli

Copy link
Copy Markdown

Rationale for this change

Unwrapped google.protobuf.Timestamp fields are always written as TIMESTAMP(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.timestampUnit setting, accepting MILLIS, MICROS (default is still NANOS):

  • ProtoWriteSupport reads the setting and converts the unwrapped Timestamp value to that unit's epoch count.
  • ProtoSchemaConverter annotates the column as TIMESTAMP(unit,true) so the footer schema matches the stored values.
  • An unrecognized value fails at write time with a BadConfigurationException naming the setting instead of silently producing a mismatched column.
  • parquet-protobuf/README.md documents 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 a Configuration, and the NANOS default.
  • ProtoWriteSupportTest: micros and millis round trips through a real Parquet file, the exact addLong value 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):

mvn -pl parquet-protobuf test        # 138 tests, 0 failures
mvn -pl parquet-protobuf spotless:check

Are there any user-facing changes?

Yes, additively: parquet.proto.timestampUnit is a new optional setting. Behavior without it is unchanged.

Closes #3972

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet-protobuf, support configurable(but limited!) time precision during unwrap

1 participant