uros-b commented on code in PR #56407:
URL: https://github.com/apache/spark/pull/56407#discussion_r3409975041
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala:
##########
@@ -484,6 +484,37 @@ private[parquet] class ParquetRowConverter(
}
}
+ // The TIMESTAMP(NANOS) parquet type postdates Spark's switch to the
proleptic Gregorian
+ // calendar, so no legacy hybrid-calendar writer could have produced it.
Nanos values are
+ // always proleptic Gregorian and are exempt from datetime rebasing
+ // (`spark.sql.parquet.datetimeRebaseModeInRead` only covers DATE,
TIMESTAMP_MILLIS and
+ // TIMESTAMP_MICROS).
+ case _: TimestampLTZNanosType
+ if
parquetType.getLogicalTypeAnnotation.isInstanceOf[TimestampLogicalTypeAnnotation]
&&
+ parquetType.getLogicalTypeAnnotation
+ .asInstanceOf[TimestampLogicalTypeAnnotation].getUnit ==
TimeUnit.NANOS =>
+ new ParquetPrimitiveConverter(updater) {
+ override def addLong(value: Long): Unit = {
+ val epochMicros = Math.floorDiv(value,
DateTimeConstants.NANOS_PER_MICROS)
+ val nanosWithinMicro =
+ Math.floorMod(value, DateTimeConstants.NANOS_PER_MICROS).toShort
+ this.updater.set(TimestampNanosVal.fromParts(epochMicros,
nanosWithinMicro))
+ }
+ }
+
+ case _: TimestampNTZNanosType
+ if
parquetType.getLogicalTypeAnnotation.isInstanceOf[TimestampLogicalTypeAnnotation]
&&
+ parquetType.getLogicalTypeAnnotation
+ .asInstanceOf[TimestampLogicalTypeAnnotation].getUnit ==
TimeUnit.NANOS =>
+ new ParquetPrimitiveConverter(updater) {
+ override def addLong(value: Long): Unit = {
+ val epochMicros = Math.floorDiv(value,
DateTimeConstants.NANOS_PER_MICROS)
+ val nanosWithinMicro =
+ Math.floorMod(value, DateTimeConstants.NANOS_PER_MICROS).toShort
+ this.updater.set(TimestampNanosVal.fromParts(epochMicros,
nanosWithinMicro))
+ }
+ }
+
Review Comment:
The TimestampLTZNanosType and TimestampNTZNanosType cases in
ParquetRowConverter have identical bodies, and each evaluates
parquetType.getLogicalTypeAnnotation three times in the guard. Consider a small
shared helper (e.g. makeNanosConverter(updater)) and binding the annotation
once.
--
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]