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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/UnwrapCastInBinaryComparison.scala:
##########
@@ -293,6 +297,34 @@ object UnwrapCastInBinaryComparison extends 
Rule[LogicalPlan] {
     }
   }
 
+  /**
+   * Move the cast to the literal side, because we can only get the minimum 
value of timestamp,
+   * so some BinaryComparison needs to be changed,
+   * such as CAST(ts AS date) > DATE '2023-01-01' ===> ts >= TIMESTAMP 
'2023-01-02 00:00:00'
+   */
+  private def unwrapDateToTimestamp(
+      exp: BinaryComparison,
+      fromExp: Expression,
+      date: Literal,
+      tz: Option[String],
+      evalMode: EvalMode.Value): Expression = {
+    val dateAddOne = DateAdd(date, Literal(1, IntegerType))
+    exp match {
+      case _: GreaterThan =>
+        GreaterThanOrEqual(fromExp, Cast(dateAddOne, fromExp.dataType, tz, 
evalMode))
+      case _: GreaterThanOrEqual =>
+        GreaterThanOrEqual(fromExp, Cast(date, fromExp.dataType, tz, evalMode))
+      case Equality(_, _) =>

Review Comment:
   I think this is wrong for `EqualNullSafe`. If the column value is null, then 
`EqualNullSafe` should return false, but the rewritten expression returns null.



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