Skip to content

[SPARK-57160][CONNECT] Add Spark Connect protocol support for nanosecond-capable timestamp types and literals - #56909

Closed
MaxGekk wants to merge 1 commit into
apache:masterfrom
MaxGekk:nanos-proto
Closed

[SPARK-57160][CONNECT] Add Spark Connect protocol support for nanosecond-capable timestamp types and literals#56909
MaxGekk wants to merge 1 commit into
apache:masterfrom
MaxGekk:nanos-proto

Conversation

@MaxGekk

@MaxGekkMaxGekk commented Jun 30, 2026

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

This PR adds the Spark Connect protocol surface for nanosecond timestamps so they can travel over the wire, both as types and as literals. There is no behavior change yet -- the converters that consume these messages land in follow-up sub-tasks of SPARK-56822.

  • types.proto: two new data-type kinds, TimestampNTZNanos and TimestampLTZNanos, each with an optional precision (7..9).
  • expressions.proto: matching literal arms that carry the value as epoch_micros + nanos_within_micro (0..999) plus an optional precision. Two components are used instead of a single int64 of nanoseconds because nanoseconds-since-epoch cannot cover the full 0001..9999 year range; this mirrors the Catalyst value TimestampNanosVal.
  • Regenerated the Python stubs under python/pyspark/sql/connect/proto/.

NTZ and LTZ are kept as separate kinds/arms (like timestamp vs timestamp_ntz), and non-negative fields use uint32.

Why are the changes needed?

Today the Connect DataType message has only microsecond timestamp kinds (timestamp, timestamp_ntz) with no precision field, and the Expression.Literal message encodes timestamp literals as a single int64 of microseconds. There is no way to express a nanosecond-capable timestamp type or a sub-microsecond literal over the wire, so no Connect client/server path can carry the new types. The protocol must be extended before any converter, Arrow, or client work can proceed.

Does this PR introduce any user-facing change?

No. This only adds protobuf message definitions; the new types remain gated behind spark.sql.timestampNanosTypes.enabled once the consuming paths are implemented.

How was this patch tested?

  • buf build / buf lint succeed for the modified protos (field numbers appended, no reuse/renumber).
  • ./dev/connect-gen-protos.sh regenerates the committed Python stubs; ./dev/check-protos.py reports no drift (pyspark-connect and pyspark-streaming: SUCCESS).
  • build/sbt "connect/testOnly *LiteralExpressionProtoConverterSuite" (44 tests) and build/sbt "connect-client-jvm/testOnly *ColumnNodeToProtoConverterSuite" (18 tests) pass, confirming the additive proto fields do not break existing proto plumbing.

No functional tests in this PR (there are no consumers of the new fields yet); behavior is covered by the converter and end-to-end sub-tasks.

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

Generated-by: Cursor (Claude Opus 4.8)

…ond-capable timestamp types and literals
Extend the Spark Connect protobuf protocol to represent TimestampNTZNanos(p)
and TimestampLTZNanos(p) (p in [7, 9]) both as data types and as literal
values, and regenerate the Python stubs.

@yadavay-amznyadavay-amzn 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.

LGTM with a small nit

Clean, well-scoped protocol addition - field numbers are allocated correctly and the encoding faithfully mirrors the Catalyst value type.

Nit: the DataType TimestampNTZNanos/TimestampLTZNanos messages don't state the omitted-precision default, while the literal arms do ("defaults to 9"). Since the type defaults to 9 too (TimestampNTZNanosType.apply()), mirroring that one-liner would keep them symmetric.

What I verified:

  • Field numbers append past the literal oneof's reserved 27, 28 (Geometry/Geography) and the DataType oneof's used range - additive and wire-compatible, no reuse or renumber.
  • epoch_micros + nanos_within_micro in [0, 999] matches Catalyst TimestampNanosVal (epochMicros, MAX_NANOS_WITHIN_MICRO = 999); the two-component encoding matches why a single int64 of nanos can't span the year range.
  • Precision 7/8/9 and default 9 match Timestamp{NTZ,LTZ}NanosType (MIN_PRECISION/MAX_PRECISION/DEFAULT_PRECISION).
  • NTZ and LTZ as separate kinds/arms is consistent with the existing timestamp vs timestamp_ntz split.

@MaxGekk

Copy link
Copy Markdown
MemberAuthor

Merging to master/4.x. Thank you, @yadavay-amzn and @zhengruifeng for review.

MaxGekk added a commit that referenced this pull request Jul 1, 2026
…ond-capable timestamp types and literals
### What changes were proposed in this pull request?
This PR adds the Spark Connect protocol surface for nanosecond timestamps so they can travel over the wire, both as types and as literals. There is no behavior change yet -- the converters that consume these messages land in follow-up sub-tasks of SPARK-56822.
- `types.proto`: two new data-type kinds, `TimestampNTZNanos` and `TimestampLTZNanos`, each with an optional `precision` (7..9).
- `expressions.proto`: matching literal arms that carry the value as `epoch_micros` + `nanos_within_micro` (0..999) plus an optional `precision`. Two components are used instead of a single int64 of nanoseconds because nanoseconds-since-epoch cannot cover the full `0001..9999` year range; this mirrors the Catalyst value `TimestampNanosVal`.
- Regenerated the Python stubs under `python/pyspark/sql/connect/proto/`.
NTZ and LTZ are kept as separate kinds/arms (like `timestamp` vs `timestamp_ntz`), and non-negative fields use `uint32`.
### Why are the changes needed?
Today the Connect `DataType` message has only microsecond timestamp kinds (`timestamp`, `timestamp_ntz`) with no precision field, and the `Expression.Literal` message encodes timestamp literals as a single int64 of microseconds. There is no way to express a nanosecond-capable timestamp type or a sub-microsecond literal over the wire, so no Connect client/server path can carry the new types. The protocol must be extended before any converter, Arrow, or client work can proceed.
### Does this PR introduce _any_ user-facing change?
No. This only adds protobuf message definitions; the new types remain gated behind `spark.sql.timestampNanosTypes.enabled` once the consuming paths are implemented.
### How was this patch tested?
- `buf build` / `buf lint` succeed for the modified protos (field numbers appended, no reuse/renumber).
- `./dev/connect-gen-protos.sh` regenerates the committed Python stubs; `./dev/check-protos.py` reports no drift (pyspark-connect and pyspark-streaming: SUCCESS).
- `build/sbt "connect/testOnly *LiteralExpressionProtoConverterSuite"` (44 tests) and `build/sbt "connect-client-jvm/testOnly *ColumnNodeToProtoConverterSuite"` (18 tests) pass, confirming the additive proto fields do not break existing proto plumbing.
No functional tests in this PR (there are no consumers of the new fields yet); behavior is covered by the converter and end-to-end sub-tasks.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor (Claude Opus 4.8)
Closes#56909 from MaxGekk/nanos-proto.
Authored-by: Maxim Gekk <max.gekk@gmail.com>
Signed-off-by: Max Gekk <max.gekk@gmail.com>
(cherry picked from commit bc72d93)
Signed-off-by: Max Gekk <max.gekk@gmail.com>
@MaxGekk

Copy link
Copy Markdown
MemberAuthor

Merge summary (posted by merge_spark_pr.py):

dongjoon-hyun added a commit to apache/spark-connect-swift that referenced this pull request Aug 7, 2026
…th `branch-4.3 (2026-08-07)`
### What changes were proposed in this pull request?
This PR updates the `Spark Connect`-generated Swift source code by regenerating with `branch-4.3 (2026-08-07)`
- apache/spark#56300
- apache/spark#56909
- apache/spark#57412
### Why are the changes needed?
To keep the generated Swift source code in sync with Apache Spark `branch-4.3` protobuf definitions.
```
$ git clone -b branch-4.3 https://github.com/apache/spark.git
$ cd spark/sql/connect/common/src/main/protobuf/
$ protoc --swift_out=. spark/connect/*.proto
$ protoc --grpc-swift_out=. spark/connect/*.proto
// Remove empty GRPC files
$ cd spark/connect
$ grep 'This file contained no services' * | awk -F: '{print $1}' | xargs rm
```
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Fable 5
Closes#490 from dongjoon-hyun/SPARK-58652.
Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for freeto 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

@MaxGekk@zhengruifeng@yadavay-amzn