You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "tshauck (via GitHub)" <gi...@apache.org> on 2024/06/03 15:09:21 UTC
[PR] Support negatives in split part [datafusion]
tshauck opened a new pull request, #10780:
URL: https://github.com/apache/datafusion/pull/10780
## Which issue does this PR close?
Closes #10761
## Rationale for this change
Postgres at least supports negative index in split_part. It'd be nice to for datafusion to similarly, since `split_part(..., ..., -1)` is not unheard of.
## What changes are included in this PR?
Updated code and tests.
## Are these changes tested?
Yes, added new sqllogictests and updated exists unittests.
## Are there any user-facing changes?
User queries which may've failed no longer will.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support negatives in split part [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #10780:
URL: https://github.com/apache/datafusion/pull/10780
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Support negatives in split part [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #10780:
URL: https://github.com/apache/datafusion/pull/10780#discussion_r1624904885
##########
datafusion/functions/src/string/split_part.rs:
##########
@@ -97,14 +97,21 @@ fn split_part<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> {
.zip(n_array.iter())
.map(|((string, delimiter), n)| match (string, delimiter, n) {
(Some(string), Some(delimiter), Some(n)) => {
- if n <= 0 {
- exec_err!("field position must be greater than zero")
- } else {
- let split_string: Vec<&str> = string.split(delimiter).collect();
- match split_string.get(n as usize - 1) {
- Some(s) => Ok(Some(*s)),
- None => Ok(Some("")),
+ let split_string: Vec<&str> = string.split(delimiter).collect();
+ let len = split_string.len();
+
+ let index = match n.cmp(&0) {
+ std::cmp::Ordering::Less => len as i64 + n,
Review Comment:
so negative parts mean "index from end" rather than index from beginning? Makes sense to me.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org