Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/21935#discussion_r206983054
--- Diff:
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroDeserializer.scala
---
@@ -86,8 +87,14 @@ class AvroDeserializer(rootAvroType: Schema,
rootCatalystType: DataType) {
case (LONG, LongType) => (updater, ordinal, value) =>
updater.setLong(ordinal, value.asInstanceOf[Long])
- case (LONG, TimestampType) => (updater, ordinal, value) =>
- updater.setLong(ordinal, value.asInstanceOf[Long] * 1000)
+ case (LONG, TimestampType) => avroType.getLogicalType match {
+ case _: TimestampMillis => (updater, ordinal, value) =>
+ updater.setLong(ordinal, value.asInstanceOf[Long] * 1000)
+ case _: TimestampMicros => (updater, ordinal, value) =>
+ updater.setLong(ordinal, value.asInstanceOf[Long])
+ case _ => (updater, ordinal, value) =>
+ updater.setLong(ordinal, value.asInstanceOf[Long] * 1000)
--- End diff --
Let's add a comment to say it's for backward compatibility reasons. Also we
should only do it when logical type is null. For other logical types, we should
fail here.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]