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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ResolveDefaultColumnsUtil.scala:
##########
@@ -311,36 +313,35 @@ object ResolveDefaultColumns extends QueryErrorsBase
       defaultSQL: String): Expression = {
     val supplanted = CharVarcharUtils.replaceCharVarcharWithString(dataType)
     // Perform implicit coercion from the provided expression type to the 
required column type.
-    val ret = if (supplanted == analyzed.dataType) {
-      analyzed
-    } else if (Cast.canUpCast(analyzed.dataType, supplanted)) {
-      Cast(analyzed, supplanted)
-    } else {
-      // If the provided default value is a literal of a wider type than the 
target column, but the
-      // literal value fits within the narrower type, just coerce it for 
convenience. Exclude
-      // boolean/array/struct/map types from consideration for this type 
coercion to avoid
-      // surprising behavior like interpreting "false" as integer zero.
-      val result = if (analyzed.isInstanceOf[Literal] &&
-        !Seq(supplanted, analyzed.dataType).exists(_ match {
+    val ret = analyzed match {
+      case equivalent if equivalent.dataType == supplanted =>
+        equivalent
+      case canUpCast if Cast.canUpCast(canUpCast.dataType, supplanted) =>
+        Cast(analyzed, supplanted, Some(conf.sessionLocalTimeZone))
+      case l: Literal
+        if !Seq(supplanted, l.dataType).exists(_ match {
           case _: BooleanType | _: ArrayType | _: StructType | _: MapType => 
true
           case _ => false
-        })) {
-        try {
-          val casted = Cast(analyzed, supplanted, evalMode = 
EvalMode.TRY).eval()

Review Comment:
   shall we make the change smaller and only add the missing timezone here?



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