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


##########
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:
   Literals from 1582-10-05 to 1582-10-14 still pass this check. Those dates 
don't exist in the hybrid calendar, so the rebase moves them to 1582-10-15 at 
the same time of day: `TIMESTAMP'1582-10-10 18:00:00'` is checked as 
`1582-10-15 18:00:00.0` and pushed with that later value. On 4.2.0, with four 
one-row files at 1582-10-15 00:00, 06:00, 12:00 and 23:30 (UTC), `t >= 
TIMESTAMP'1582-10-10 18:00:00'` returns 1 with pushdown on and 4 with it off. 
`>`, `!=` and `NOT IN` lose rows the same way.
   
   This predates the PR but is the symptom it fixes. With the Java 8 API off, 
the filter already holds the shifted `Timestamp`, so the original date isn't 
available here. Could the cutoff move to a wall clock of 1582-10-16 00:00? Both 
new tests could add a 1582-10-10 literal as a condition value (as data it reads 
back as 1582-10-15), and the `1582-10-15T01:00:00` case would flip to `false`.



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