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

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ##########
 @@ -246,6 +247,54 @@ class Analyzer(
       CleanupAliases)
   )
 
+  /**
+   * 1. Turns Add/Subtract of DateType/TimestampType/StringType and 
CalendarIntervalType
+   *    to TimeAdd/TimeSub.
+   * 2. Turns Add/Subtract of TimestampType/DateType/IntegerType
+   *    and TimestampType/IntegerType/DateType to 
DateAdd/DateSub/SubtractDates and
+   *    to SubtractTimestamps.
+   * 3. Turns Multiply/Divide of CalendarIntervalType and NumericType
+   *    to MultiplyInterval/DivideInterval
+   */
+  case class ResolveBinaryArithmetic(conf: SQLConf) extends Rule[LogicalPlan] {
+    override def apply(plan: LogicalPlan): LogicalPlan = 
plan.resolveOperatorsUp {
+      case p: LogicalPlan => p.transformExpressionsUp {
+        case UnresolvedAdd(l, r) => (l.dataType, r.dataType) match {
+          case (TimestampType | DateType | StringType, CalendarIntervalType) =>
+            Cast(TimeAdd(l, r), l.dataType)
+          case (CalendarIntervalType, TimestampType | DateType | StringType) =>
+            Cast(TimeAdd(r, l), r.dataType)
+          case (DateType, _) => DateAdd(l, r)
 
 Review comment:
   Hi @cloud-fan, when I was implementing this, I got a bit confused.
   Our date_sub/date_add actually support implicit type cast, that is
   ```
   select date_add(date'1900-01-01', 1);
   select date_add(date'1900-01-01', 1.2);
   select date_add(date'1900-01-01', "1.2");
   ```
   are supported, and result the same.
   
   but while using `date'1900-01-01' + 1`, we only support int. Is this 
nonconforming?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to