You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/03/20 11:49:52 UTC

[GitHub] [spark] maropu commented on a change in pull request #27965: [SPARK-31205][SQL] support string literal as the second argument of date_add/date_sub functions

maropu commented on a change in pull request #27965: [SPARK-31205][SQL] support string literal as the second argument of date_add/date_sub functions
URL: https://github.com/apache/spark/pull/27965#discussion_r395585654
 
 

 ##########
 File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
 ##########
 @@ -1043,6 +1044,22 @@ object TypeCoercion {
       }
     }
   }
+
+  /**
+   * A special rule to support string literal as the second argument of date_add/date_sub functions,
+   * to keep backward compatibility.
+   * TODO: revisit the type coercion rules for string.
+   */
+  object StringLiteralCoercion extends TypeCoercionRule {
+    override protected def coerceTypes(plan: LogicalPlan): LogicalPlan = plan resolveExpressions {
+      // Skip nodes who's children have not been resolved yet.
+      case e if !e.childrenResolved => e
+      case DateAdd(l, r) if r.dataType == StringType && r.foldable =>
+        DateAdd(l, AnsiCast(r, IntegerType))
 
 Review comment:
   Ah, yes. I rechecked the references of implicit casts in some databases, as you said, the cast seems to be acceptable.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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