ueshin commented on code in PR #45796:
URL: https://github.com/apache/spark/pull/45796#discussion_r1547142056


##########
connector/connect/common/src/main/protobuf/spark/connect/expressions.proto:
##########
@@ -137,6 +137,13 @@ message Expression {
     }
   }
 
+  enum EvalMode {
+    EVAL_MODE_UNSPECIFIED = 0;
+    EVAL_MODE_LEGACY = 1;
+    EVAL_MODE_ANSI = 2;
+    EVAL_MODE_TRY = 3;
+  }

Review Comment:
   I'm wondering whether we should put this here or in Cast message?



##########
sql/core/src/main/scala/org/apache/spark/sql/Column.scala:
##########
@@ -1222,6 +1222,43 @@ class Column(val expr: Expression) extends Logging {
    */
   def cast(to: String): Column = cast(CatalystSqlParser.parseDataType(to))
 
+  /**
+   * Casts the column to a different data type and the result is null on 
failure.
+   * {{{
+   *   // Casts colA to IntegerType.
+   *   import org.apache.spark.sql.types.IntegerType
+   *   df.select(df("colA").try_cast(IntegerType))
+   *
+   *   // equivalent to
+   *   df.select(df("colA").try_cast("int"))
+   * }}}
+   *
+   * @group expr_ops
+   * @since 4.0.0
+   */
+  def try_cast(to: DataType): Column = withExpr {
+    val cast = Cast(
+      child = expr,
+      dataType = CharVarcharUtils.replaceCharVarcharWithStringForCast(to),
+      evalMode = EvalMode.TRY)
+    cast.setTagValue(Cast.USER_SPECIFIED_CAST, ())

Review Comment:
   Just curious, what is this tag doing?



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