You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Weijun-H (via GitHub)" <gi...@apache.org> on 2024/03/20 15:42:54 UTC
[PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Weijun-H opened a new pull request, #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #9706
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9710:
URL: https://github.com/apache/datafusion/pull/9710#issuecomment-2136370571
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.
--
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] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "Weijun-H (via GitHub)" <gi...@apache.org>.
Weijun-H commented on PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#issuecomment-2011833385
> @Weijun-H I think the common logic for them is not large enough to worth mixing into one function. Do you think separate the function for them is easier for understanding the code? I'm even thinking of `union` and `intersect` too.
The three function logic structures are similar, so I think they should be merged into one. @jayzhan211
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#issuecomment-2011742092
@Weijun-H I think the common logic for them is not large enough to worth mixing into one function. Do you think separate the function for them is easier for understanding the code? I'm even thinking of `union` and `intersect` too.
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#discussion_r1533518043
##########
datafusion/functions-array/src/set_ops.rs:
##########
@@ -273,55 +284,88 @@ fn generic_set_lists<OffsetSize: OffsetSizeTrait>(
let mut offsets = vec![OffsetSize::usize_as(0)];
let mut new_arrays = vec![];
+ let mut nulls = vec![];
let converter = RowConverter::new(vec![SortField::new(dt)])?;
for (first_arr, second_arr) in l.iter().zip(r.iter()) {
- if let (Some(first_arr), Some(second_arr)) = (first_arr, second_arr) {
- let l_values = converter.convert_columns(&[first_arr])?;
- let r_values = converter.convert_columns(&[second_arr])?;
-
- let l_iter = l_values.iter().sorted().dedup();
- let values_set: HashSet<_> = l_iter.clone().collect();
- let mut rows = if set_op == SetOp::Union {
- l_iter.collect::<Vec<_>>()
- } else {
- vec![]
- };
- for r_val in r_values.iter().sorted().dedup() {
- match set_op {
- SetOp::Union => {
- if !values_set.contains(&r_val) {
- rows.push(r_val);
- }
- }
- SetOp::Intersect => {
- if values_set.contains(&r_val) {
- rows.push(r_val);
- }
- }
+ let last_offset = match offsets.last().copied() {
+ Some(offset) => offset,
+ None => return internal_err!("offsets should not be empty"),
+ };
+ let (l_values, r_values) = match (first_arr, second_arr) {
+ (Some(_), None) if set_op == SetOp::Intersect => {
+ offsets.push(last_offset);
+ nulls.push(false);
+ continue;
+ }
+ (None, Some(_)) if matches!(set_op, SetOp::Intersect | SetOp::Except) => {
+ offsets.push(last_offset);
+ nulls.push(false);
+ continue;
+ }
+ (None, None) => {
+ offsets.push(last_offset);
+ nulls.push(false);
+ continue;
+ }
+ (first_arr, second_arr) => {
+ let first_arr = first_arr.unwrap_or(new_empty_array(&l.value_type()));
+ let second_arr = second_arr.unwrap_or(new_empty_array(&r.value_type()));
+ let l_values = converter.convert_columns(&[first_arr])?;
+ let r_values = converter.convert_columns(&[second_arr])?;
+ // swap l_values and r_values if set_op is Except, because the values
+ // in the second array should be removed from the first array
+ if set_op == SetOp::Except {
+ (r_values, l_values)
+ } else {
+ (l_values, r_values)
}
}
+ };
- let last_offset = match offsets.last().copied() {
- Some(offset) => offset,
- None => return internal_err!("offsets should not be empty"),
- };
- offsets.push(last_offset + OffsetSize::usize_as(rows.len()));
- let arrays = converter.convert_rows(rows)?;
- let array = match arrays.first() {
- Some(array) => array.clone(),
- None => {
- return internal_err!("{set_op}: failed to get array from rows");
+ let l_iter = l_values.iter().sorted().dedup();
+ let values_set: HashSet<_> = l_iter.clone().collect();
+ let mut rows = if set_op == SetOp::Union {
+ l_iter.collect::<Vec<_>>()
+ } else {
+ vec![]
+ };
+ for r_val in r_values.iter().sorted().dedup() {
+ match set_op {
+ SetOp::Union | SetOp::Except => {
+ if !values_set.contains(&r_val) {
+ rows.push(r_val);
+ }
}
- };
- new_arrays.push(array);
+ SetOp::Intersect => {
+ if values_set.contains(&r_val) {
+ rows.push(r_val);
+ }
+ }
+ }
}
+
+ offsets.push(last_offset + OffsetSize::usize_as(rows.len()));
+ let arrays = converter.convert_rows(rows)?;
+ let array = match arrays.first() {
Review Comment:
I recently learn `swap_remove`, I think we can apply here without clone. `arrays.swap_remove(0)`
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#discussion_r1533169937
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -405,6 +405,18 @@ AS VALUES
(arrow_cast(make_array([5,6], [5,6], NULL, NULL, NULL), 'FixedSizeList(5, List(Int64))'))
;
+statement ok
+CREATE TABLE array_setop_with_NULL_table
Review Comment:
you can name it `array_setop` for all the setop functions, because we don't need special non-null table
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#discussion_r1533168276
##########
datafusion/functions-array/src/set_ops.rs:
##########
@@ -273,55 +284,97 @@ fn generic_set_lists<OffsetSize: OffsetSizeTrait>(
let mut offsets = vec![OffsetSize::usize_as(0)];
let mut new_arrays = vec![];
+ let mut nulls = vec![];
let converter = RowConverter::new(vec![SortField::new(dt)])?;
for (first_arr, second_arr) in l.iter().zip(r.iter()) {
- if let (Some(first_arr), Some(second_arr)) = (first_arr, second_arr) {
- let l_values = converter.convert_columns(&[first_arr])?;
- let r_values = converter.convert_columns(&[second_arr])?;
-
- let l_iter = l_values.iter().sorted().dedup();
- let values_set: HashSet<_> = l_iter.clone().collect();
- let mut rows = if set_op == SetOp::Union {
- l_iter.collect::<Vec<_>>()
- } else {
- vec![]
- };
- for r_val in r_values.iter().sorted().dedup() {
- match set_op {
- SetOp::Union => {
- if !values_set.contains(&r_val) {
- rows.push(r_val);
+ let last_offset = match offsets.last().copied() {
+ Some(offset) => offset,
+ None => return internal_err!("offsets should not be empty"),
+ };
+ match (first_arr, second_arr) {
+ (Some(first_arr), Some(second_arr)) => {
+ let mut l_values = converter.convert_columns(&[first_arr])?;
+ let mut r_values = converter.convert_columns(&[second_arr])?;
+
+ if set_op == SetOp::Except {
+ (l_values, r_values) = (r_values, l_values);
Review Comment:
I think mixing the logic of except here make it less readable 😕
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#issuecomment-2027357037
What is the status of this PR ? it isn't clear to me if it was waiting on more feedback
I saw it did several changes at once (like both move code and add features) which meant it was hard for me to find enough time to review.
If there is still work to be done, perhaps we can do the changes in two PRs (move the code, and then fix / add functionality)
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#discussion_r1533169937
##########
datafusion/sqllogictest/test_files/array.slt:
##########
@@ -405,6 +405,18 @@ AS VALUES
(arrow_cast(make_array([5,6], [5,6], NULL, NULL, NULL), 'FixedSizeList(5, List(Int64))'))
;
+statement ok
+CREATE TABLE array_setop_with_NULL_table
Review Comment:
you can name it `array_setop`. for all the setop functions
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #9710: fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect`
URL: https://github.com/apache/datafusion/pull/9710
--
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] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#issuecomment-2011955412
How about extract the common to function. And, try to let the logic for one
stay close together.
One of issue I think that make it less readable is that for example array
except, we need to go through several if else statements that is unrelated
(union or intersect), and even swapping for the common function.
I think I need suggestions from others too, maybe it is easy to read for
others.
On Thu, Mar 21, 2024, 6:14 PM Alex Huang ***@***.***> wrote:
> @Weijun-H <https://github.com/Weijun-H> I think the common logic for them
> is not large enough to worth mixing into one function. Do you think
> separate the function for them is easier for understanding the code? I'm
> even thinking of union and intersect too.
>
> The three function logic structures are similar, so I think they should be
> merged into one. @jayzhan211 <https://github.com/jayzhan211>
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/apache/arrow-datafusion/pull/9710#issuecomment-2011833385>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADZCLR2LQ46JY6UGPDDTGJTYZKXKDAVCNFSM6AAAAABE7XPNPOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJRHAZTGMZYGU>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: move array_except in SetOp and support Null columnar in `array_except`, `array_union` and `array_intersect` [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #9710:
URL: https://github.com/apache/arrow-datafusion/pull/9710#issuecomment-2027357279
Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look
--
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@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org