findepi commented on code in PR #12141:
URL: https://github.com/apache/datafusion/pull/12141#discussion_r1729460747
##########
datafusion/functions/src/unicode/substr.rs:
##########
@@ -144,19 +144,25 @@ where
let result = iter
.zip(start_array.iter())
.zip(count_array.iter())
- .map(|((string, start), count)| match (string, start, count) {
- (Some(string), Some(start), Some(count)) => {
- if count < 0 {
- exec_err!(
+ .map(|((string, start), count)| {
+ match (string, start, count) {
+ (Some(string), Some(start), Some(count)) => {
+ if count < 0 {
+ exec_err!(
"negative substring length not allowed:
substr(<str>, {start}, {count})"
)
- } else {
- let skip = max(0, start - 1);
- let count = max(0, count + (if start < 1 {start -
1} else {0}));
- Ok(Some(string.chars().skip(skip as
usize).take(count as usize).collect::<String>()))
+ } else {
+ let skip_value = start.checked_sub(1);
+ if skip_value.is_none() {
+ return exec_err!("negative overflow when
calculating skip value");
+ }
+ let skip = max(0, skip_value.unwrap());
Review Comment:
i think i should be able to use `ok_or_else(|| exec_err! ...)?` here, but
couldn't get it to work.
i was able to do this only when using `exec_datafusion_err!` (because it
creates error, not a Result). are `exec_datafusion_err!` and `exec_err!
equivalent in how they construct the error?
--
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]