[WIP][SPARK-56981][SQL] Add physical representation and UnsafeRow support for nanosecond timestamps#56059
Open
MaxGekk wants to merge 6 commits into
Open
[WIP][SPARK-56981][SQL] Add physical representation and UnsafeRow support for nanosecond timestamps#56059MaxGekk wants to merge 6 commits into
MaxGekk wants to merge 6 commits into
Conversation
Register physical types and UnsafeRow/InternalRow accessors for TimestampNTZNanosType and TimestampLTZNanosType so values can be stored and read using the SPIP composite layout (epoch micros + sub-micro nanos).
…anosSuite Wrap the `assertThrows` calls in `invalidNanosWithinMicroNTZ`/`LTZ` so each line stays within the 100-character limit enforced by checkstyle. Co-authored-by: Isaac
…estamps Route nullable TIMESTAMP_NTZ/LTZ nanos fields through UnsafeWriter.write instead of setNull8Bytes so the 16-byte variable-length region is reserved and in-place setTimestampNTZNanos/LTZ remains valid.
…ndian safety writePayload stores nanos via putLong; reading with getShort returned zero on big-endian. Match the write path with getLong and a 16-bit mask.
…timestamps Document unsafe projection support for TimestampNTZNanosType and TimestampLTZNanosType instead of relying only on DatetimeType extending AtomicType. Add a test to pin the contract.
…types Provide defaults in Literal.defaultDefault so planning rules that call Literal.default on TimestampNTZNanosType/TimestampLTZNanosType (e.g. outer- join null replacement, window tolerance) don't throw noDefaultForDataTypeError. 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?
This PR implements the physical row layer for nanosecond-capable timestamp types, as defined in SPARK-56822 SPIP: Timestamps with nanosecond precision.
Logical types
TimestampNTZNanosType(p)andTimestampLTZNanosType(p)(p in [7, 9]) were added in #55952; they still mapped toUninitializedPhysicalType, so values could not be stored or read fromInternalRow/UnsafeRow. This change wires up the minimum physical infrastructure that downstream work (casts, Parquet, expressions) can depend on.SPIP internal representation
Per the SPIP, a value is a composite of:
Logical defaultSize remains 10 bytes on the types. In UnsafeRow, values use the same variable-length pattern as CalendarInterval: an 8-byte field slot (offset + size) pointing to a 16-byte aligned payload (epochMicros + nanosWithinMicro with padding), so in-place updates remain possible.
Implementation summary
TimestampNTZNanos- physical value forTIMESTAMP_NTZ(p)TimestampLTZNanos- physical value forTIMESTAMP_LTZ(p)PhysicalTimestampNTZNanosType,PhysicalTimestampLTZNanosTyperegistered inPhysicalDataType.applyDefaultInternalRow,UnsafeRow,UnsafeArrayData, codegen (CodeGenerator,InterpretedUnsafeProjection,SpecializedGettersReader), and literal validationColumnVectorstubs throwSparkUnsupportedOperationExceptionuntil columnar support is addedWhy are the changes needed?
Without a concrete physical type and
UnsafeRowaccessors, any code path that materializes rows for nanosecond timestamps fails or falls through toUninitializedPhysicalType. This is the unblocker for the rest of sub-tasks.Does this PR introduce any user-facing change?
No. Logical types exist but are not yet exposed through SQL; behavior of
TimestampType,TimestampNTZType, and microsecond storage is unchanged.How was this patch tested?
unsafe/testOnly *TimestampNanosSuite— unsafe value equality, hashCode, validation (nanosWithinMicro∈ [0, 999])catalyst/testOnly *TimestampNanosRowSuite—GenericInternalRowandUnsafeRowroundtrips (NTZ + LTZ, null/non-null), codegen and interpreted unsafe projection, literal validationDataTypeSuite—PhysicalDataTypeis notUninitializedPhysicalTypefor p in {7, 8, 9};defaultSizeremains 10Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor Auto