Skip to content

[GH-3609]: Add new sort order for int96 timestamps#3610

Open
divjotarora wants to merge 5 commits into
apache:masterfrom
divjotarora:int96-stats
Open

[GH-3609]: Add new sort order for int96 timestamps#3610
divjotarora wants to merge 5 commits into
apache:masterfrom
divjotarora:int96-stats

Conversation

@divjotarora

@divjotarora divjotarora commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

See parquet-format proposal for rationale: apache/parquet-format#584

What changes are included in this PR?

Add new INT96_TIMESTAMP_ORDER sort order and related parsing.

Are these changes tested?

Yes, new unit tests.

Are there any user-facing changes?

Two new flags and a Thrift change.

Closes #3609

Comment thread parquet-column/src/main/java/org/apache/parquet/column/ParquetProperties.java Outdated
Comment thread parquet-column/src/main/java/org/apache/parquet/schema/ColumnOrder.java Outdated
Comment thread parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveComparator.java Outdated
Comment thread parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveType.java Outdated
Comment thread parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java Outdated
Comment thread parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetInputFormat.java Outdated
@wgtmac

wgtmac commented Jun 25, 2026

Copy link
Copy Markdown
Member

Please resolve the conflicts.

@divjotarora

Copy link
Copy Markdown
Contributor Author

Please resolve the conflicts.

@wgtmac Sorry for the delay, I was on holiday last week. Conflicts are resolved now

*
* Two-level comparison, matching the INT96 timestamp sort order:
* 1. Compare the last 4 bytes (Julian day) as a signed little-endian int32.
* 2. If equal, compare the first 8 bytes (nanos) as a signed little-endian int64.

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.

The correctness of this depends on the two fields so I think we have to be more careful since the caller may pass in something unexpected.

I think that we need to validate that the nanosecond value is positive and less than the number of nanoseconds per day. If either of these is violated, then this sort order is no longer correct.

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.

Added validation for both cases

Comment thread parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveType.java Outdated
* min/max statistics in place. This simulates a legacy writer that emitted INT96 stats under
* TYPE_ORDER before INT96_TIMESTAMP_ORDER existed; such stats must be ignored by the reader.
*/
private static void downgradeInt96ToTypeOrder(FileMetaData footer) {

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.

Can you add a couple more cases? I'd like to see UNDEFINED, TYPE_DEFINED_ORDER, and unset cases.

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.

Removed this helper and added both testReaderIgnoresInt96StatsWithTypeDefinedOrder and testReaderIgnoresInt96StatsWhenColumnOrdersAbsent

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 wasn't able to test UNDEFINED as I didn't find a good way to serialize an undefined value for the union

@rdblue

rdblue commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

I think there are a few things to be fixed, but overall I trust that this works.

@divjotarora divjotarora requested a review from rdblue July 13, 2026 16:51
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.

Add new sort order for int96 timestamps

3 participants