MaxGekk commented on code in PR #56825:
URL: https://github.com/apache/spark/pull/56825#discussion_r3485963424


##########
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:
   Added in `725770c` - new test "SPARK-57459: reading a foreign nanos Avro 
file with an explicit lower-precision schema": writes a full-precision 
(`...567890123`) foreign `timestamp-nanos` / `local-timestamp-nanos` file with 
no catalyst-type prop, reads it with an explicit `TIMESTAMP_LTZ(7)` / 
`TIMESTAMP_NTZ(7)` schema, and asserts the sub-microsecond digits are truncated 
(`...123` -> `...100`), mirroring `ParquetTimestampNanosSuite`.



-- 
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