cloud-fan commented on a change in pull request #26412: [SPARK-29774][SQL] Date 
and Timestamp type +/- null should be null as Postgres
URL: https://github.com/apache/spark/pull/26412#discussion_r353115036
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ##########
 @@ -246,6 +247,68 @@ class Analyzer(
       CleanupAliases)
   )
 
+  /**
+   * For [[UnresolvedAdd]]:
+   * 1. If one side is timestamp/date/string and the other side is interval, 
turns it to
+   * [[TimeAdd]];
+   * 2. else if one side is date, turns it to [[DateAdd]] ;
+   * 3. else turns it to [[Add]].
+   *
+   * For [[UnresolvedSubtract]]:
+   * 1. If the left side is timestamp/date/string and the right side is an 
interval, turns it to
+   * [[TimeSub]];
+   * 2. else if one side is timestamp and the other side is date/timestamp, 
turns it to
+   * [[SubtractTimestamps]];
+   * 3. else if both side are dates, turns it to 
[[DateDiff]]/[[SubtractDates]];
+   * 4. else if the left side is date, turns it to [[DateSub]];
+   * 5. else turns it to [[Subtract]].
+   *
+   * For [[UnresolvedMultiply]]:
+   * 1. If one side is interval and the other side is numeric, turns it to 
[[MultiplyInterval]];
+   * 2. otherwise, turns it to [[Multiply]].
+   *
+   * For [[UnresolvedDivide]]:
+   * 1. If the left side is interval and the right side is numeric, turns it to
+   * [[DivideInterval]];
+   * 2. otherwise, turns it to [[Divide]].
+   */
+  case class ResolveBinaryArithmetic(conf: SQLConf) extends Rule[LogicalPlan] {
+    override def apply(plan: LogicalPlan): LogicalPlan = 
plan.resolveOperatorsUp {
+      case p: LogicalPlan => p.transformExpressionsUp {
+        case u @ UnresolvedAdd(l, r) if u.childrenResolved => (l.dataType, 
r.dataType) match {
+          case (TimestampType | DateType | StringType, CalendarIntervalType) =>
 
 Review comment:
   according to the above discussion, I think it's clearer to do
   ```
   case (CalendarIntervalType, CalendarIntervalType) => Add
   case (_, CalendarIntervalType) => TimeAdd
   case (CalendarIntervalType, _) => TimeAdd
   case (_, DateType) => DateAdd
   case (DateType, _) => DateAdd
   case _ => Add
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to