zhengruifeng commented on code in PR #47249:
URL: https://github.com/apache/spark/pull/47249#discussion_r1669467512


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/planner/SparkConnectPlanner.scala:
##########
@@ -2178,20 +2178,23 @@ class SparkConnectPlanner(
   }
 
   private def transformCast(cast: proto.Expression.Cast): Expression = {
-    val dataType = cast.getCastToTypeCase match {
+    val rawDataType = cast.getCastToTypeCase match {
       case proto.Expression.Cast.CastToTypeCase.TYPE => 
transformDataType(cast.getType)
       case _ => parser.parseDataType(cast.getTypeStr)
     }
-    val mode = cast.getEvalMode match {
-      case proto.Expression.Cast.EvalMode.EVAL_MODE_LEGACY => 
Some(EvalMode.LEGACY)
-      case proto.Expression.Cast.EvalMode.EVAL_MODE_ANSI => Some(EvalMode.ANSI)
-      case proto.Expression.Cast.EvalMode.EVAL_MODE_TRY => Some(EvalMode.TRY)
-      case _ => None
-    }
-    mode match {
-      case Some(m) => Cast(transformExpression(cast.getExpr), dataType, None, 
m)
-      case _ => Cast(transformExpression(cast.getExpr), dataType)
+    val dataType = 
CharVarcharUtils.replaceCharVarcharWithStringForCast(rawDataType)
+    val castExpr = cast.getEvalMode match {
+      case proto.Expression.Cast.EvalMode.EVAL_MODE_LEGACY =>
+        Cast(transformExpression(cast.getExpr), dataType, None, 
EvalMode.LEGACY)

Review Comment:
   I guess it is affected by `castExpr.setTagValue(Cast.USER_SPECIFIED_CAST, 
())`
   
   
https://github.com/apache/spark/blob/0487507c8fe0d0ac50515aff84f41e146d1cd51d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/package.scala#L93-L110



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