Weijun-H commented on code in PR #9019:
URL: https://github.com/apache/arrow-datafusion/pull/9019#discussion_r1472451034
##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -885,6 +885,11 @@ nary_scalar_expr!(
scalar_expr!(DatePart, date_part, part date, "extracts a subfield from the
date");
scalar_expr!(DateTrunc, date_trunc, part date, "truncates the date to a
specified level of precision");
scalar_expr!(DateBin, date_bin, stride source origin, "coerces an arbitrary
timestamp to the start of the nearest specified interval");
+nary_scalar_expr!(
+ ToDate,
+ to_date,
+ "converts a string and optional formats to a `Date32`"
Review Comment:
```suggestion
"converts string to date according to the given format"
```
##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -396,6 +396,39 @@ fn string_to_timestamp_nanos_shim(s: &str) -> Result<i64> {
string_to_timestamp_nanos(s).map_err(|e| e.into())
}
+fn to_date_impl(args: &[ColumnarValue], name: &str) -> Result<ColumnarValue> {
+ match args.len() {
+ 1 => handle::<Date32Type, _, Date32Type>(
+ args,
+ |s| {
+ string_to_timestamp_nanos_shim(s)
+ .map(|n| n / (1_000_000 * 24 * 60 * 60 * 1_000))
+ .and_then(|v| {
+ v.try_into().map_err(|_| {
+ internal_datafusion_err!("Unable to cast to Date32
for converting from i64 to i32 failed")
+ })
+ })
+ },
+ name,
+ ),
Review Comment:
Maybe we can use `to_timestamp_impl` to avoid code duplication.
```suggestion
1 => to_timestamp_impl::<TimestampNanosecondType>(args, name),
```
--
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]