Skip to content

[SPARK-57839][SQL] Support the nanosecond-precision timestamp types in CBO statistics estimation#56941

Open
yadavay-amzn wants to merge 1 commit into
apache:masterfrom
yadavay-amzn:SPARK-57839
Open

[SPARK-57839][SQL] Support the nanosecond-precision timestamp types in CBO statistics estimation#56941
yadavay-amzn wants to merge 1 commit into
apache:masterfrom
yadavay-amzn:SPARK-57839

Conversation

@yadavay-amzn

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Adds cost-based optimizer (CBO) statistics estimation support for the nanosecond-precision timestamp types (TimestampNTZNanosType, TimestampLTZNanosType), mirroring the existing microsecond TimestampType handling at every CBO site: EstimationUtils.toDouble/fromDouble, FilterEstimation.evaluateBinary/evaluateInSet, UnionEstimation.isTypeSupported, and CatalogColumnStat min/max (de)serialization. Values are converted on the nanosecond scale (epochMicros * 1000 + nanosWithinMicro). Column-stat min/max are serialized with a fraction-preserving 9-digit nanosecond formatter so they round-trip losslessly.

Why are the changes needed?

Filters/joins/unions over nanosecond-precision timestamp columns previously fell back to default selectivity because these types were not among the types CBO estimates. They have a natural numeric ordering, so they can be estimated the same way as microsecond timestamps.

Does this PR introduce any user-facing change?

No. Affects CBO estimation / plan costing only; query results are unchanged.

How was this patch tested?

New FilterEstimationSuite tests (range / = / IN selectivity) for the nanosecond types, nanosecond columns added to the Union/Join estimation tests, and a dedicated lossless min/max round-trip test in StatisticsCollectionSuite (a sub-microsecond value survives toExternalString -> fromExternalString). All CBO estimation suites pass.

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

Authored with assistance by Claude Opus 4.8.

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.

1 participant