Skip to content

[SPARK-58743][SQL][TESTS] Add nanosecond-timestamp coverage for mode - #57966

Open
stevomitric wants to merge 2 commits into
apache:masterfrom
stevomitric:stevomitric/nanos-mode-tests
Open

[SPARK-58743][SQL][TESTS] Add nanosecond-timestamp coverage for mode#57966
stevomitric wants to merge 2 commits into
apache:masterfrom
stevomitric:stevomitric/nanos-mode-tests

Conversation

@stevomitric

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add an end-to-end test to TimestampNanosFunctionsSuiteBase (run in both ANSI modes) asserting that mode returns the most-frequent value keyed on the full nanos value (the frequent and rare values differ only within the microsecond) and preserves the input precision and family (NTZ/LTZ). Also add a deterministic golden SQL case (mode(...) with a unique most-frequent value) to timestamp-ntz-nanos.sql / timestamp-ltz-nanos.sql.

Why are the changes needed?

Extend test coverage for timestamp nanosecond precision datatype.

Does this PR introduce any user-facing change?

No, test only change.

How was this patch tested?

Test only change.

Was this patch authored or co-authored using generative AI tooling?

Co-Authored-By: Claude Code 4.8

`mode` counts frequencies in an `OpenHashMap` keyed on the physical
`TimestampNanosVal` (its `equals`/`hashCode` cover the full
`(epochMicros, nanosWithinMicro)` pair) and returns `child.dataType`. It
already works over the nanosecond timestamp types (`TIMESTAMP_NTZ(p)` /
`TIMESTAMP_LTZ(p)`, p in [7, 9]) but had no dedicated test coverage.

Add an end-to-end test to `TimestampNanosFunctionsSuiteBase` (run in both ANSI
modes) asserting that mode returns the most-frequent value keyed on the full
nanos value (the frequent and rare values differ only within the microsecond)
and preserves the input precision and family (NTZ/LTZ). Also add a
deterministic golden SQL case (`mode(...)` with a unique most-frequent value)
to `timestamp-ntz-nanos.sql` / `timestamp-ltz-nanos.sql`.

Test-only; no production change.

Co-authored-by: Isaac
@stevomitric stevomitric changed the title [SPARK-58743][SQL][TESTS] Add nanosecond-timestamp coverage for mode [WIP][SPARK-58743][SQL][TESTS] Add nanosecond-timestamp coverage for mode Aug 12, 2026
@stevomitric stevomitric changed the title [WIP][SPARK-58743][SQL][TESTS] Add nanosecond-timestamp coverage for mode [SPARK-58743][SQL][TESTS] Add nanosecond-timestamp coverage for mode Aug 12, 2026
@stevomitric

Copy link
Copy Markdown
Contributor Author

cc @uros-b, @cloud-fan PTAL when you get a chance.

@uros-b

uros-b commented Aug 12, 2026

Copy link
Copy Markdown
Member

Nice, thank you @stevomitric!

@cloud-fan cloud-fan 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.

0 blocking, 0 non-blocking, 0 nits.
The coverage is deterministic, exercises the intended full-nanosecond distinction, and is consistent across the Scala and SQL golden test surfaces.

Verification

I traced the added inputs through the existing Mode aggregate and TimestampNanosVal equality/hash behavior, checked that the hot and cold values remain distinct at every tested precision, and reconciled the generated analyzer schemas and outputs with the queries. I did not run the Spark test suites.

PR metadata suggestions

  • Document: replace Test only change in the testing section with the exact suites or commands run and their results.

@uros-b

uros-b commented Aug 12, 2026

Copy link
Copy Markdown
Member

@stevomitric Please fix lint issues.

Reflow an over-long comment line in TimestampNanosFunctionsSuiteBase to
stay within the 100-character limit. Comment-only change.

Co-authored-by: Isaac
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.

3 participants