uros-b commented on code in PR #56825:
URL: https://github.com/apache/spark/pull/56825#discussion_r3485923474
##########
sql/core/src/main/scala/org/apache/spark/sql/avro/AvroDeserializer.scala:
##########
@@ -213,6 +213,28 @@ private[sql] class AvroDeserializer(
s"Avro logical type $other cannot be converted to SQL type
${TimeType().sql}.")
}
+ case (LONG, t: TimestampLTZNanosType) => avroType.getLogicalType match {
+ // The timestamp-nanos logical type stores epoch-nanoseconds (Long),
while the value is
+ // represented internally as (epochMicros, nanosWithinMicro). Floor
semantics keep
+ // nanosWithinMicro in [0, 999] for pre-epoch values. Nanos timestamps
are always proleptic
+ // Gregorian, so they are exempt from datetime rebasing.
+ case _: TimestampNanos => (updater, ordinal, value) =>
+ updater.set(ordinal,
+ DateTimeUtils.epochNanosToTimestampNanos(value.asInstanceOf[Long],
t.precision))
+ case other => throw new IncompatibleSchemaException(errorPrefix +
+ s"Avro logical type $other cannot be converted to SQL type " +
+ s"${TimestampLTZNanosType().sql}.")
+ }
+
+ case (LONG, t: TimestampNTZNanosType) => avroType.getLogicalType match {
+ case _: LocalTimestampNanos => (updater, ordinal, value) =>
+ updater.set(ordinal,
+ DateTimeUtils.epochNanosToTimestampNanos(value.asInstanceOf[Long],
t.precision))
Review Comment:
Nit: Parquet has one test Avro still lacks: explicit lower-precision read
schema. Parquet’s ParquetTimestampNanosSuite verifies that reading a
full-precision foreign file with TIMESTAMP_NTZ(7) truncates sub-precision
digits. Avro’s deserializer uses the same epochNanosToTimestampNanos(value,
t.precision) path, so behavior should match; but there’s no Avro test pinning
it. A small test mirroring Parquet’s “explicit lower-precision read schema”
case would close the loop.
--
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]