cloud-fan commented on code in PR #44480:
URL: https://github.com/apache/spark/pull/44480#discussion_r1436991316


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala:
##########
@@ -144,6 +144,21 @@ object UnwrapCastInBinaryComparison extends 
Rule[LogicalPlan] {
           value != null =>
       Some(unwrapTimestampToDate(be, fromExp, ts, timeZoneId, evalMode))
 
+    // Timestamp/Timestamp_NTZ -> Timestamp_NTZ/Timestamp
+    case be @ BinaryComparison(
+      c @ Cast(fromExp, _, timeZoneId, evalMode), Literal(value, literalType))
+        if AnyTimestampType.acceptsType(fromExp.dataType) &&
+          AnyTimestampType.acceptsType(literalType) && value != null =>
+      // datetime with timezone is tricky, do a round trip to check if the 
rewrite is okay.
+      val newCast = Cast(Literal(value, literalType), fromExp.dataType, 
timeZoneId, evalMode)
+      val roundTrip = Cast(newCast, literalType, timeZoneId, evalMode)
+      if (roundTrip.eval().asInstanceOf[Long] == value.asInstanceOf[Long]) {
+        val newExpr = be.withNewChildren(Seq(fromExp, newCast))
+        Some(newExpr)
+      } else {
+        None
+      }
+

Review Comment:
   Not related to this PR, but I just noticed that people keep supporting new 
data types in binary comparison, but not `In` and `InSet`. It will be better if 
we can somehow unify the code between `In/InSet` and binary comparison.
   
   cc @wangyum 



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