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_r353222500
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -246,6 +247,65 @@ class Analyzer(
CleanupAliases)
)
+ /**
+ * For [[UnresolvedAdd]]:
+ * 1. if both side are interval, turns it to [[Add]];
+ * 2. else if one side is interval, turns it to [[TimeAdd]];
+ * 3. else if one side is date, turns it to [[DateAdd]] ;
+ * 4. else turns it to [[Add]].
+ *
+ * For [[UnresolvedSubtract]]:
+ * 1. if both side are interval, turns it to [[Subtract]];
+ * 2. else if the right side is an interval, turns it to [[TimeSub]];
+ * 3. else if one side is timestamp, turns it to [[SubtractTimestamps]];
+ * 4. else if the right side is date, turns it to
[[DateDiff]]/[[SubtractDates]];
+ * 5. else if the left side is date, turns it to [[DateSub]];
+ * 6. else turns it to [[Subtract]].
+ *
+ * For [[UnresolvedMultiply]]:
+ * 1. If one side is interval, turns it to [[MultiplyInterval]];
+ * 2. otherwise, turns it to [[Multiply]].
+ *
+ * For [[UnresolvedDivide]]:
+ * 1. If the left side is interval, 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 (CalendarIntervalType, CalendarIntervalType) => Add(l, r)
+ case (_, CalendarIntervalType) => Cast(TimeAdd(l, r), l.dataType)
+ case (CalendarIntervalType, _) => Cast(TimeAdd(r, l), r.dataType)
+ case (DateType, _) => DateAdd(l, r)
+ case (_, DateType) => DateAdd(r, l)
+ case _ => Add(l, r)
+ }
+ case u @ UnresolvedSubtract(l, r) if u.childrenResolved =>
(l.dataType, r.dataType) match {
+ case (CalendarIntervalType, CalendarIntervalType) => Subtract(l, r)
+ case (_, CalendarIntervalType) => Cast(TimeSub(l, r), l.dataType)
+ case (TimestampType, _) => SubtractTimestamps(l, r)
+ case (_, TimestampType) => SubtractTimestamps(Cast(l,
TimestampType), r)
Review comment:
no, I'll remove this cast, it's legacy
----------------------------------------------------------------
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]