cloud-fan commented on code in PR #44480: URL: https://github.com/apache/spark/pull/44480#discussion_r1436440200
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala: ########## @@ -144,6 +144,15 @@ object UnwrapCastInBinaryComparison extends Rule[LogicalPlan] { value != null => Some(unwrapTimestampToDate(be, fromExp, ts, timeZoneId, evalMode)) + // Timestamp/Timestamp_NTZ -> Timestamp_NTZ/Timestamp Review Comment: `cast(ts_ntz_col as ts) compare ts_lit` means `convertTz(col_value, tz, UTC) compare lit_value`, and we are trying to reverse it to `col_value compare convertTz(lit_value, UTC, tz)`. We need to be careful here, as datetime with timezone is very tricky. My proposal is to do a round trip tests before rewriting it: if `convertTz(convertTz(lit_value, UTC, tz), tz, UTC) == lit_value`. This means we convert the comparison to `convertTz(col_value, tz, UTC) compare convertTz(convertTz(lit_value, UTC, tz), tz, UTC) == lit_value` first, and we strip the `convertTz(_, tz, UTC)` from both sides. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org