Skip to content

[SPARK-58742][SQL][TESTS] Add nanosecond-timestamp coverage for collect_set - #57965

Open
stevomitric wants to merge 1 commit into
apache:masterfrom
stevomitric:stevomitric/nanos-collect-set-tests
Open

[SPARK-58742][SQL][TESTS] Add nanosecond-timestamp coverage for collect_set#57965
stevomitric wants to merge 1 commit into
apache:masterfrom
stevomitric:stevomitric/nanos-collect-set-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 collect_set deduplicates on the full nanosecond value: sub-microsecond-distinct values stay distinct at p=9 but collapse when floored below the grid at p in [7, 8]. Also add a deterministic golden SQL case (sort_array(collect_set(...))) 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

…ct_set

`collect_set` deduplicates via a `HashSet` keyed on the physical
`TimestampNanosVal`, whose `equals`/`hashCode` cover the full
`(epochMicros, nanosWithinMicro)` pair, so sub-microsecond-distinct values are
kept distinct; the result element type is exactly `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 collect_set deduplicates on the full nanosecond value:
sub-microsecond-distinct values stay distinct at p=9 but collapse when floored
below the grid at p in [7, 8]. Also add a deterministic golden SQL case
(`sort_array(collect_set(...))`) to `timestamp-ntz-nanos.sql` /
`timestamp-ltz-nanos.sql`.

Test-only; no production change.

Co-authored-by: Isaac
@stevomitric stevomitric changed the title [SPARK-58742][SQL][TESTS] Add nanosecond-timestamp coverage for collect_set [WIP][SPARK-58742][SQL][TESTS] Add nanosecond-timestamp coverage for collect_set Aug 12, 2026
@stevomitric stevomitric changed the title [WIP][SPARK-58742][SQL][TESTS] Add nanosecond-timestamp coverage for collect_set [SPARK-58742][SQL][TESTS] Add nanosecond-timestamp coverage for collect_set 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

Looks good, 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 added coverage is internally consistent and exercises the intended precision-sensitive deduplication behavior.

Verification

I traced the new assertions through the precision-specific inputs and checked the generated SQL results: the precision-9 cases retain the two sub-microsecond-distinct values, while the focused Scala test expects the correctly floored single value at precisions 7 and 8. The contract scan also verified the comments against CollectSet, TimestampNanosVal equality/hash behavior, timestamp flooring, and sort_array.

PR metadata suggestions

  • Explain the relationship between SPARK-58742 in the PR title and SPARK-56822 in the added test names/comments, or align the identifiers.

@uros-b

uros-b commented Aug 12, 2026

Copy link
Copy Markdown
Member

@stevomitric Please fix lint issues.

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