LuciferYang commented on code in PR #60293:
URL: https://github.com/apache/spark/pull/60293#discussion_r4549937213


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/orc/OrcFilters.scala:
##########
@@ -285,10 +293,47 @@ private[sql] object OrcFilters extends OrcFiltersBase {
 
     import org.apache.spark.sql.sources._
 
+    // Spark writes TimestampType values to ORC in the hybrid Julian/Gregorian 
calendar, and
+    // `castLiteralValue` converts a pushed down value the same way. But ORC 
compares the value
+    // with the statistics after converting the ones whose wall clock is 
before 1582-10-15 to the
+    // proleptic Gregorian calendar (see `DateUtils.convertTimeToProleptic`), 
which moves them by
+    // up to 10 days. So a predicate with a value whose wall clock is before 
1582-10-15 is not
+    // pushed down. A later value compares the same with a converted statistic 
as with the stored
+    // one, as both are earlier than it. ORC compares wall clocks in the JVM 
default time zone,
+    // and its wall clock is computed here as in 
`SerializationUtils.convertToUtc`.
+    def hasValueBeforeCalendarSwitch(attribute: String, values: Seq[Any]): 
Boolean =
+      dataTypeMap.get(attribute).exists(_.fieldType == TimestampType) && {
+        val timeZone = TimeZone.getDefault
+        values.exists { v =>
+          castLiteralValue(v, TimestampType) match {
+            case ts: Timestamp =>
+              val millis = ts.getTime
+              millis + timeZone.getOffset(millis) < GregorianSwitchMillis

Review Comment:
   Thanks, that matches what I see. I scanned every JVM zone with the 4.2.0 
jars: on tzdata 2025b the latest wall clock that a 1582-10-05 to 1582-10-14 
value moves to is 1582-10-16 00:59:59 (America/Asuncion), and none reach 
1582-10-17. On tzdata 2026b America/Vancouver joins the list with the same 
maximum, so the 10-17 cutoff still leaves about a day of margin. The second 
test also catches a 10-16 cutoff in UTC through `1582-10-16T23:59:59.999999 -> 
false`, whatever the tzdata. LGTM.



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