Jefffrey commented on code in PR #19134:
URL: https://github.com/apache/datafusion/pull/19134#discussion_r2595757317


##########
datafusion/functions/src/datetime/to_date.rs:
##########
@@ -144,9 +146,36 @@ impl ScalarUDFImpl for ToDateFunc {
         }
 
         match args[0].data_type() {
-            Int32 | Int64 | Null | Float64 | Date32 | Date64 => {
+            Null | Int32 | Int64 | Date32 | Date64 | Timestamp(_, _) => {
                 args[0].cast_to(&Date32, None)
             }
+            UInt8 | UInt16 | UInt32 | UInt64 | Int8 | Int16 => {
+                // Arrow cast doesn't support direct casting of these types to 
date32
+                // as it only supports Int32 and Int64. To work around that 
limitation,
+                // use cast_with_options to cast to Int32 and then cast the 
result of
+                // that to Date32.
+                match &args[0] {
+                    ColumnarValue::Array(array) => {
+                        Ok(ColumnarValue::Array(cast_with_options(
+                            &cast_with_options(&array, &Int32, 
&DEFAULT_CAST_OPTIONS)?,
+                            &Date32,
+                            &DEFAULT_CAST_OPTIONS,
+                        )?))
+                    }
+                    ColumnarValue::Scalar(scalar) => {
+                        let sv =
+                            scalar.cast_to_with_options(&Int32, 
&DEFAULT_CAST_OPTIONS)?;
+                        Ok(ColumnarValue::Scalar(
+                            sv.cast_to_with_options(&Date32, 
&DEFAULT_CAST_OPTIONS)?,
+                        ))
+                    }
+                }
+            }
+            Float16 | Float32 | Float64 => {

Review Comment:
   ```suggestion
               Float16 | Float32 | Float64 | Decimal32(_, _) | Decimal64(_, _) 
| Decimal128(_, _) | Decimal256(_, _) => {
   ```
   
   Then in the description can simplify as:
   
   > Supports strings, numeric and timestamp types as input.



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