You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/24 03:48:31 UTC

[GitHub] [arrow-datafusion] liukun4515 opened a new pull request, #4355: fix bug: right anti join with filter

liukun4515 opened a new pull request, #4355:
URL: https://github.com/apache/arrow-datafusion/pull/4355

   # 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 #4247
   
   Fix the bug `right anti` join with filter
   
   # 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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4355: fix bug: right anti join with filter

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #4355:
URL: https://github.com/apache/arrow-datafusion/pull/4355#discussion_r1031952633


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -884,32 +904,27 @@ fn build_join_indexes(
             for (row, hash_value) in hash_values.iter().enumerate() {
                 // Get the hash and find it in the build index
 
-                // For every item on the left and right we check if it doesn't match
+                // For every item on the left and right we check if it matches
                 // This possibly contains rows with hash collisions,
                 // So we have to check here whether rows are equal or not
-                // We only produce one row if there is no match
-                let matches = left.0.get(*hash_value, |(hash, _)| *hash_value == *hash);
-                let mut no_match = true;
-                match matches {
-                    Some((_, indices)) => {
-                        for &i in indices {
-                            // Check hash collisions
-                            if equal_rows(
-                                i as usize,
-                                row,
-                                &left_join_values,
-                                &keys_values,
-                                *null_equals_null,
-                            )? {
-                                no_match = false;
-                                break;
-                            }
+                // After get all matched right size and left size, it may be filtered by the join_filter
+                // After filter, use the bitmap and get the unmatched right size row
+                if let Some((_, indices)) =
+                    left.0.get(*hash_value, |(hash, _)| *hash_value == *hash)
+                {
+                    for &i in indices {
+                        // Check hash collisions
+                        if equal_rows(
+                            i as usize,
+                            row,
+                            &left_join_values,
+                            &keys_values,
+                            *null_equals_null,
+                        )? {
+                            left_indices.append(i);
+                            right_indices.append(row as u32);
                         }
                     }

Review Comment:
   > Can't it be combined with the other cases like `JoinType::Inner` (code is the same now?)
   
   yes, I am working on this and refactor the code and combine all same logic together.
   
   So we can hold this pr and wait for the next refactored pr 



-- 
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


[GitHub] [arrow-datafusion] mingmwang commented on a diff in pull request #4355: fix bug: right anti join with filter

Posted by GitBox <gi...@apache.org>.
mingmwang commented on code in PR #4355:
URL: https://github.com/apache/arrow-datafusion/pull/4355#discussion_r1031192779


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -884,32 +904,27 @@ fn build_join_indexes(
             for (row, hash_value) in hash_values.iter().enumerate() {
                 // Get the hash and find it in the build index
 
-                // For every item on the left and right we check if it doesn't match
+                // For every item on the left and right we check if it matches
                 // This possibly contains rows with hash collisions,
                 // So we have to check here whether rows are equal or not
-                // We only produce one row if there is no match
-                let matches = left.0.get(*hash_value, |(hash, _)| *hash_value == *hash);
-                let mut no_match = true;
-                match matches {
-                    Some((_, indices)) => {
-                        for &i in indices {
-                            // Check hash collisions
-                            if equal_rows(
-                                i as usize,
-                                row,
-                                &left_join_values,
-                                &keys_values,
-                                *null_equals_null,
-                            )? {
-                                no_match = false;
-                                break;
-                            }
+                // After get all matched right size and left size, it may be filtered by the join_filter
+                // After filter, use the bitmap and get the unmatched right size row
+                if let Some((_, indices)) =
+                    left.0.get(*hash_value, |(hash, _)| *hash_value == *hash)
+                {
+                    for &i in indices {
+                        // Check hash collisions
+                        if equal_rows(
+                            i as usize,
+                            row,
+                            &left_join_values,
+                            &keys_values,
+                            *null_equals_null,
+                        )? {
+                            left_indices.append(i);
+                            right_indices.append(row as u32);
                         }
                     }

Review Comment:
   Nice! This makes the right anti join logic much more simpler and more consistent with the other join types !
    



-- 
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


[GitHub] [arrow-datafusion] liukun4515 commented on pull request #4355: fix bug: right anti join with filter

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #4355:
URL: https://github.com/apache/arrow-datafusion/pull/4355#issuecomment-1327523984

   convert this pr to draft, and file a new pr to refactor the hash join.
   The new pr can also resolve this issue


-- 
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


[GitHub] [arrow-datafusion] liukun4515 closed pull request #4355: fix bug: right anti join with filter

Posted by GitBox <gi...@apache.org>.
liukun4515 closed pull request #4355: fix bug: right anti join with filter
URL: https://github.com/apache/arrow-datafusion/pull/4355


-- 
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


[GitHub] [arrow-datafusion] Dandandan commented on a diff in pull request #4355: fix bug: right anti join with filter

Posted by GitBox <gi...@apache.org>.
Dandandan commented on code in PR #4355:
URL: https://github.com/apache/arrow-datafusion/pull/4355#discussion_r1031636126


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -884,32 +904,27 @@ fn build_join_indexes(
             for (row, hash_value) in hash_values.iter().enumerate() {
                 // Get the hash and find it in the build index
 
-                // For every item on the left and right we check if it doesn't match
+                // For every item on the left and right we check if it matches
                 // This possibly contains rows with hash collisions,
                 // So we have to check here whether rows are equal or not
-                // We only produce one row if there is no match
-                let matches = left.0.get(*hash_value, |(hash, _)| *hash_value == *hash);
-                let mut no_match = true;
-                match matches {
-                    Some((_, indices)) => {
-                        for &i in indices {
-                            // Check hash collisions
-                            if equal_rows(
-                                i as usize,
-                                row,
-                                &left_join_values,
-                                &keys_values,
-                                *null_equals_null,
-                            )? {
-                                no_match = false;
-                                break;
-                            }
+                // After get all matched right size and left size, it may be filtered by the join_filter
+                // After filter, use the bitmap and get the unmatched right size row
+                if let Some((_, indices)) =
+                    left.0.get(*hash_value, |(hash, _)| *hash_value == *hash)
+                {
+                    for &i in indices {
+                        // Check hash collisions
+                        if equal_rows(
+                            i as usize,
+                            row,
+                            &left_join_values,
+                            &keys_values,
+                            *null_equals_null,
+                        )? {
+                            left_indices.append(i);
+                            right_indices.append(row as u32);
                         }
                     }

Review Comment:
   Can't it be combined with the other cases like `JoinType::Inner` (code is the same now?)



-- 
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