MaxGekk opened a new pull request, #56807:
URL: https://github.com/apache/spark/pull/56807

   ### What changes were proposed in this pull request?
   
   This PR adds support for the Spark `TIME` (`TimeType`) data type in the 
Protobuf connector (`to_protobuf` / `from_protobuf`), matching the existing 
Avro support added in SPARK-54473.
   
   Spark `TimeType` is mapped to a plain Protobuf `int64` field holding the 
number of nanoseconds since midnight (nanoseconds-of-day). Since `TimeType` is 
stored internally as nanoseconds since midnight, the conversion is a direct 
copy of the `Long` value (no unit math).
   
   - `ProtobufSerializer`: added a `(TimeType, LONG)` case that writes a 
`TimeType` column into an `int64` field as nanos-of-day.
   - `ProtobufDeserializer`: added a `(LONG, TimeType)` case that reads an 
`int64` field back into a `TimeType` value.
   - `docs/sql-data-sources-protobuf.md`: documented the new `TimeType` -> 
`int64 (nanoseconds-of-day)` mapping.
   
   Note: a bare Protobuf `int64` carries no logical-type marker, and 
`from_protobuf` always derives its output schema from the descriptor via 
`SchemaConverters.toSqlType`. Therefore `from_protobuf` infers such a field as 
`LongType` (nanoseconds-of-day), which can be cast back to `TIME` with 
`CAST(... AS TIME)`. The `int64 -> TimeType` deserializer path is exercised 
when a `ProtobufDeserializer` is constructed with an explicit `TimeType` schema.
   
   ### Why are the changes needed?
   
   To extend support for the TIME data type to the Protobuf connector, closing 
the gap noted in SPARK-57573 where `SchemaConverters`/serializer/deserializer 
had no `TimeType` mapping. This is a sub-task of SPARK-57550 (Extend support 
for the TIME data type).
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `to_protobuf` now accepts `TIME` columns, writing them to a Protobuf 
`int64` field as nanoseconds-of-day, and the Protobuf data source documentation 
lists the new mapping.
   
   ### How was this patch tested?
   
   Added tests in `ProtobufFunctionsSuite`:
   - `SPARK-57573: Handle TimeType between to_protobuf and from_protobuf` - 
verifies a `TIME` column serializes to the `int64` field and reads back as 
`LongType` equal to `LocalTime.toNanoOfDay`.
   - `SPARK-57573: TimeType roundtrip through ProtobufSerializer and 
ProtobufDeserializer` - direct serializer/deserializer round trip with an 
explicit `TimeType` schema, covering precisions (`TimeType(0)`, `TimeType(6)`) 
and boundary values (`00:00:00`, `23:59:59.999999`).
   
   All existing `ProtobufFunctionsSuite`, `ProtobufSerdeSuite`, and 
`ProtobufCatalystDataConversionSuite` tests pass.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Cursor


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to