[WIP][SPARK-57823][SQL] Support ORC predicate pushdown for nanosecond-precision timestamps - #57681
Open
stevomitric wants to merge 1 commit into
Open
Conversation
…ision timestamps ### What changes were proposed in this pull request? Enable ORC predicate pushdown for nanosecond-precision timestamp columns (`TIMESTAMP_LTZ(p)` / `TIMESTAMP_NTZ(p)`, `p` in [7, 9]). `OrcFilters.getPredicateLeafType` / `castLiteralValue` route framework types through `OrcTypeOps`, but both nanos ops inherited the default `predicateLeafType = None`. A pushed filter on a nanos column therefore reached the throwing arm of `getPredicateLeafType` and failed the query. This wires the two nanos ops (`TimestampLTZNanosOrcOps` / `TimestampNTZNanosOrcOps`) into the pushdown seam: - `predicateLeafType` now returns `Some(PredicateLeaf.Type.TIMESTAMP)`, matching the physical ORC category the types are stored in (`TIMESTAMP` for NTZ, `TIMESTAMP_INSTANT` for LTZ). - `castFilterLiteral` converts the external filter literal to a plain `java.sql.Timestamp` whose local wall clock equals the value's nominal wall clock, so the pushed value compares consistently against the ORC min/max statistics: - NTZ (`java.time.LocalDateTime`) -> `Timestamp.valueOf(ldt)`. - LTZ (`java.time.Instant`) -> `Timestamp.valueOf(LocalDateTime.ofInstant(i, UTC))`. Two ORC-specific details drove the literal shape: 1. ORC's `SearchArgument` builder checks the literal's class by exact equality (`value.getClass() == Type.getValueClass()`), so it rejects the `OrcTimestamp` subclass used on the write path; the literal must be a plain `java.sql.Timestamp`. 2. ORC evaluates a `TIMESTAMP` / `TIMESTAMP_INSTANT` predicate against the stored value shifted into the JVM default zone (the default `useUTCTimestamp=false` read mode Spark uses), so the literal must carry the nominal wall clock in the local zone rather than the raw epoch instant. This keeps pushdown correct regardless of the JVM time zone. Stale comments in `TimestampNanosOrcOps` / `OrcTypeOps` / `OrcFilters` that stated the nanos types had no pushdown are updated. ### Why are the changes needed? Sub-task of SPARK-56822. Without this, a filter on a nanosecond-precision timestamp ORC column throws `unsupportedOperationForDataTypeError` during planning instead of pushing the predicate down (or safely skipping it). ### Does this PR introduce any user-facing change? Yes. Predicates on nanosecond-precision timestamp ORC columns now push down to ORC search arguments (enabling stripe/row-group skipping) instead of failing. ### How was this patch tested? - New `OrcFilterSuite` test "SPARK-57823: filter pushdown - nanosecond timestamp" asserts the expected `PredicateLeaf.Operator` is generated for all comparison operators, both nanos types, and all precisions. - New `OrcQuerySuite` test "SPARK-57823: ORC predicate pushdown returns correct results for nanos timestamps" verifies end-to-end that results are correct (`checkAnswer`) and that stripes are actually skipped (`stripSparkFilter` count), across V1/V2, vectorized/non-vectorized readers, both nanos types, and all precisions. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.8) Co-authored-by: Isaac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Enable ORC predicate pushdown for nanosecond-precision timestamp columns (
TIMESTAMP_LTZ(p)/TIMESTAMP_NTZ(p),pin [7, 9]).OrcFilters.getPredicateLeafType/castLiteralValueroute framework types throughOrcTypeOps, but both nanos ops inherited the defaultpredicateLeafType = None. A pushed filter on a nanos column therefore reached the throwing arm ofgetPredicateLeafTypeand failed the query. This wires the two nanos ops (TimestampLTZNanosOrcOps/TimestampNTZNanosOrcOps) into the pushdown seam:predicateLeafTypenow returnsSome(PredicateLeaf.Type.TIMESTAMP), matching the physical ORC category the types are stored in (TIMESTAMPfor NTZ,TIMESTAMP_INSTANTfor LTZ).castFilterLiteralconverts the external filter literal to a plainjava.sql.Timestampwhose local wall clock equals the value's nominal wall clock, so the pushed value compares consistently against the ORC min/max statistics:java.time.LocalDateTime) ->Timestamp.valueOf(ldt).java.time.Instant) ->Timestamp.valueOf(LocalDateTime.ofInstant(i, UTC)).Two ORC-specific details drove the literal shape:
SearchArgumentbuilder checks the literal's class by exact equality (value.getClass() == Type.getValueClass()), so it rejects theOrcTimestampsubclass used on the write path; the literal must be a plainjava.sql.Timestamp.TIMESTAMP/TIMESTAMP_INSTANTpredicate against the stored value shifted into the JVM default zone (the defaultuseUTCTimestamp=falseread mode Spark uses), so the literal must carry the nominal wall clock in the local zone rather than the raw epoch instant. This keeps pushdown correct regardless of the JVM time zone.Stale comments in
TimestampNanosOrcOps/OrcTypeOps/OrcFiltersthat stated the nanos types had no pushdown are updated.Why are the changes needed?
Sub-task of SPARK-56822. Without this, a filter on a nanosecond-precision timestamp ORC column throws
unsupportedOperationForDataTypeErrorduring planning instead of pushing the predicate down (or safely skipping it).Does this PR introduce any user-facing change?
Yes. Predicates on nanosecond-precision timestamp ORC columns now push down to ORC search arguments (enabling stripe/row-group skipping) instead of failing.
How was this patch tested?
OrcFilterSuitetest "SPARK-57823: filter pushdown - nanosecond timestamp" asserts the expectedPredicateLeaf.Operatoris generated for all comparison operators, both nanos types, and all precisions.OrcQuerySuitetest "SPARK-57823: ORC predicate pushdown returns correct results for nanos timestamps" verifies end-to-end that results are correct (checkAnswer) and that stripes are actually skipped (stripSparkFiltercount), across V1/V2, vectorized/non-vectorized readers, both nanos types, and all precisions.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)