itsjunetime commented on code in PR #11958:
URL: https://github.com/apache/datafusion/pull/11958#discussion_r1714422858
##########
datafusion/functions/src/datetime/common.rs:
##########
@@ -227,46 +229,34 @@ where
// if the first argument is a scalar utf8 all arguments are expected
to be scalar utf8
ColumnarValue::Scalar(scalar) => match scalar {
ScalarValue::Utf8(a) | ScalarValue::LargeUtf8(a) => {
- let mut val: Option<Result<ColumnarValue>> = None;
- let mut err: Option<DataFusionError> = None;
+ let a = a.as_ref();
+ // ASK: Why do we trust `a` to be non-null at this point?
+ let a = unwrap_or_internal_err!(a);
- match a {
- Some(a) => {
- // enumerate all the values finding the first one that
returns an Ok result
- for (pos, v) in args.iter().enumerate().skip(1) {
- if let ColumnarValue::Scalar(s) = v {
- if let ScalarValue::Utf8(x) |
ScalarValue::LargeUtf8(x) =
- s
- {
- if let Some(s) = x {
- match op(a.as_str(), s.as_str()) {
- Ok(r) => {
- val =
Some(Ok(ColumnarValue::Scalar(
- S::scalar(Some(op2(r))),
- )));
- break;
- }
- Err(e) => {
- err = Some(e);
- }
- }
- }
- } else {
- return exec_err!("Unsupported data type
{s:?} for function {name}, arg # {pos}");
- }
- } else {
- return exec_err!("Unsupported data type {v:?}
for function {name}, arg # {pos}");
+ let mut ret = None;
+
+ for (pos, v) in args.iter().enumerate().skip(1) {
+ let ColumnarValue::Scalar(
+ ScalarValue::Utf8(x) | ScalarValue::LargeUtf8(x),
+ ) = v
+ else {
+ return exec_err!("Unsupported data type {v:?} for
function {name}, arg # {pos}");
+ };
+
+ if let Some(s) = x {
+ match op(a.as_str(), s.as_str()) {
+ Ok(r) => {
+ ret =
Some(Ok(ColumnarValue::Scalar(S::scalar(Some(
+ op2(r),
+ )))));
+ break;
}
+ Err(e) => ret = Some(Err(e)),
}
}
- None => (),
}
- if let Some(v) = val {
- v
- } else {
- Err(err.unwrap())
Review Comment:
Yeah, I feel like this is explicitly the thing that enums allow us to avoid
--
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]