You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Dandandan (via GitHub)" <gi...@apache.org> on 2023/06/20 09:16:41 UTC

[GitHub] [arrow-datafusion] Dandandan opened a new pull request, #6724: WIP Hash Join Vectorized collision checking

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

   # 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 #.
   
   # 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] Dandandan commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1235084737


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   Indeed - working on implementing this 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


[GitHub] [arrow-datafusion] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236474277


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   How about folding?
   
   ```rust
   pub fn equal_rows_arr(
       indices_left: UInt64Array,
       indices_right: UInt32Array,
       left_arrays: &[ArrayRef],
       right_arrays: &[ArrayRef],
       null_equals_null: bool,
   ) -> Result<(UInt64Array, UInt32Array)> {
       let mut iter = left_arrays.iter().zip(right_arrays.iter());
   
       let (first_left, first_right) = iter.next().ok_or_else(|| {
           DataFusionError::Internal("At least one array should be provided for both left and right".to_string())
       })?;
   
       let arr_left = take(first_left.as_ref(), &indices_left, None)?;
       let arr_right = take(first_right.as_ref(), &indices_right, None)?;
   
       let mut equal = eq_dyn_null(&arr_left, &arr_right, null_equals_null)?;
   
       // Use map and try_fold to iterate over the remaining pairs of arrays.
       // In each iteration, take is used on the pair of arrays and their equality is determined.
       // The results are then folded (combined) using the and function to get a final equality result.
       equal = iter
           .map(|(left, right)| {
               let arr_left = take(left.as_ref(), &indices_left, None)?;
               let arr_right = take(right.as_ref(), &indices_right, None)?;
               eq_dyn_null(arr_left.as_ref(), arr_right.as_ref(), null_equals_null)
           })
           .try_fold(equal, |acc, res| {
               let equal2 = res?;
               and(&acc, &equal2)
           })?;
       // Continue
   }
   ```



-- 
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 pull request #6724: Hash Join Vectorized collision checking

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#issuecomment-1601291308

   > LGTM, nice work @Dandandan thanks for the effort.
   
   Thanks for the feedback!


-- 
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] metesynnada commented on pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#issuecomment-1600568408

   LGTM, nice work @Dandandan thanks for the effort.


-- 
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 #6724: Hash Join Vectorized collision checking

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236484046


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(

Review Comment:
   https://github.com/apache/arrow-rs/issues/4438



-- 
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 merged pull request #6724: Hash Join Vectorized collision checking

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan merged PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724


-- 
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] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1235066157


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(

Review Comment:
   A null element can occur in an `Int32Array` as well. Maybe we should insert an option to arrow kernel, in arrow-rs.



-- 
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] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236477908


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(

Review Comment:
   I think we can open an issue on arrow-rs for this 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


[GitHub] [arrow-datafusion] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236479691


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   In addition, we do not need to take ownership of `indices_left` and `indices_right`.



-- 
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] metesynnada commented on pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#issuecomment-1598522310

   There is a significant improvement in the equality check, nice work. Maybe then the `apply_join_filter_to_indices` can be addressed, since the intermediate batch can be huge in low cardinality cases 😃


-- 
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 pull request #6724: Hash Join Vectorized collision checking

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#issuecomment-1601292106

   Btw I think this can be applied to the symmetric hash join as well without changes.


-- 
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 #6724: Hash Join Vectorized collision checking

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236503916


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   👍 



-- 
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] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1235063997


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   AFAIK `null_equals_null ` is not supported in the arrow kernel. 



-- 
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] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236474277


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   How about folding?
   
   ```rust
   pub fn equal_rows_arr(
       indices_left: UInt64Array,
       indices_right: UInt32Array,
       left_arrays: &[ArrayRef],
       right_arrays: &[ArrayRef],
       null_equals_null: bool,
   ) -> Result<(UInt64Array, UInt32Array)> {
       // Create an iterator that yields pairs of items from left_arrays and right_arrays.
       let mut iter = left_arrays.iter().zip(right_arrays.iter());
   
       // Get the first pair of arrays (or error if the iterators are empty).
       let (first_left, first_right) = iter.next().ok_or_else(|| {
           DataFusionError::Internal("At least one array should be provided for both left and right".to_string())
       })?;
   
       // Use the take function on the first pair of arrays and the respective indices.
       let arr_left = take(first_left.as_ref(), &indices_left, None)?;
       let arr_right = take(first_right.as_ref(), &indices_right, None)?;
   
       // Determine whether the first pair of arrays are equal, considering nulls as defined by null_equals_null.
       let mut equal = eq_dyn_null(&arr_left, &arr_right, null_equals_null)?;
   
       // Use map and try_fold to iterate over the remaining pairs of arrays.
       // In each iteration, take is used on the pair of arrays and their equality is determined.
       // The results are then folded (combined) using the and function to get a final equality result.
       equal = iter
           .map(|(left, right)| {
               let arr_left = take(left.as_ref(), &indices_left, None)?;
               let arr_right = take(right.as_ref(), &indices_right, None)?;
               eq_dyn_null(arr_left.as_ref(), arr_right.as_ref(), null_equals_null)
           })
           .try_fold(equal, |acc, res| {
               let equal2 = res?;
               and(&acc, &equal2)
           })?;
       // Continue
   }
   ```



-- 
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] metesynnada commented on a diff in pull request #6724: Hash Join Vectorized collision checking

Posted by "metesynnada (via GitHub)" <gi...@apache.org>.
metesynnada commented on code in PR #6724:
URL: https://github.com/apache/arrow-datafusion/pull/6724#discussion_r1236474277


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -1097,6 +1098,49 @@ pub fn equal_rows(
     err.unwrap_or(Ok(res))
 }
 
+fn eq_dyn_null(
+    left: &dyn Array,
+    right: &dyn Array,
+    null_equals_null: bool,
+) -> Result<BooleanArray, ArrowError> {
+    match (left.data_type(), right.data_type()) {
+        (DataType::Null, DataType::Null) => Ok(BooleanArray::new(
+            BooleanBuffer::collect_bool(left.len(), |_| null_equals_null),
+            None,
+        )),
+        _ => eq_dyn(left, right),
+    }
+}
+
+pub fn equal_rows_arr(
+    indices_left: UInt64Array,
+    indices_right: UInt32Array,
+    left_arrays: &[ArrayRef],
+    right_arrays: &[ArrayRef],
+    null_equals_null: bool,

Review Comment:
   ```rust
   pub fn equal_rows_arr(
       indices_left: UInt64Array,
       indices_right: UInt32Array,
       left_arrays: &[ArrayRef],
       right_arrays: &[ArrayRef],
       null_equals_null: bool,
   ) -> Result<(UInt64Array, UInt32Array)> {
       // Create an iterator that yields pairs of items from left_arrays and right_arrays.
       let mut iter = left_arrays.iter().zip(right_arrays.iter());
   
       // Get the first pair of arrays (or error if the iterators are empty).
       let (first_left, first_right) = iter.next().ok_or_else(|| {
           DataFusionError::Internal("At least one array should be provided for both left and right".to_string())
       })?;
   
       // Use the take function on the first pair of arrays and the respective indices.
       let arr_left = take(first_left.as_ref(), &indices_left, None)?;
       let arr_right = take(first_right.as_ref(), &indices_right, None)?;
   
       // Determine whether the first pair of arrays are equal, considering nulls as defined by null_equals_null.
       let mut equal = eq_dyn_null(&arr_left, &arr_right, null_equals_null)?;
   
       // Use map and try_fold to iterate over the remaining pairs of arrays.
       // In each iteration, take is used on the pair of arrays and their equality is determined.
       // The results are then folded (combined) using the and function to get a final equality result.
       equal = iter
           .map(|(left, right)| {
               let arr_left = take(left.as_ref(), &indices_left, None)?;
               let arr_right = take(right.as_ref(), &indices_right, None)?;
               eq_dyn_null(arr_left.as_ref(), arr_right.as_ref(), null_equals_null)
           })
           .try_fold(equal, |acc, res| {
               let equal2 = res?;
               and(&acc, &equal2)
           })?;
       // Continue
   }
   ```



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