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/22 13:47:46 UTC

[GitHub] [arrow-datafusion] liukun4515 opened a new pull request, #4327: fix bug: right semi join can't support the filter

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

   # 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.
   -->
   
   part of #4247 
   
   - fix bug for `right semi` join with filter and add test case for this bug
   - add test for `left semi` join with filter
   - change the name of test cases
   
   
   TODO in the next PR: fix the `right anti` join with filter; Meet some issue about the codebase, will file a new PR to fix that.
   
   @alamb @Dandandan 
   
   # 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 #4327: fix bug: right semi join can't support the filter

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


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -2371,6 +2431,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn join_right_semi_with_filter() -> Result<()> {
+        let session_ctx = SessionContext::new();
+        let task_ctx = session_ctx.task_ctx();
+        let left = build_table(
+            ("a2", &vec![10, 20, 30, 40]),
+            ("b2", &vec![4, 5, 6, 5]), // 5 is double on the left
+            ("c2", &vec![70, 80, 90, 100]),
+        );
+        let right = build_table(
+            ("a1", &vec![1, 2, 2, 3]),
+            ("b1", &vec![4, 5, 5, 7]), // 7 does not exist on the left
+            ("c1", &vec![7, 8, 8, 9]),
+        );
+
+        let on = vec![(
+            Column::new_with_schema("b2", &left.schema())?,
+            Column::new_with_schema("b1", &right.schema())?,
+        )];
+
+        // build filter left.b2 > 4
+        let column_indices = vec![ColumnIndex {
+            index: 1,
+            side: JoinSide::Left,
+        }];
+        let intermediate_schema =
+            Schema::new(vec![Field::new("x", DataType::Int32, true)]);
+
+        let filter_expression = Arc::new(BinaryExpr::new(
+            Arc::new(Column::new("x", 0)),
+            Operator::Gt,
+            Arc::new(Literal::new(ScalarValue::Int32(Some(4)))),
+        )) as Arc<dyn PhysicalExpr>;
+
+        let filter =
+            JoinFilter::new(filter_expression, column_indices, intermediate_schema);
+
+        let join =
+            join_with_filter(left, right, on, filter, &JoinType::RightSemi, false)?;
+
+        let columns = columns(&join.schema());
+        assert_eq!(columns, vec!["a1", "b1", "c1"]);
+
+        let stream = join.execute(0, task_ctx)?;
+        let batches = common::collect(stream).await?;
+
+        let expected = vec![

Review Comment:
   If not fix this bug, the result will be
   ```
   [
       "+----+----+----+",
       "| a1 | b1 | c1 |",
       "+----+----+----+",
       "+----+----+----+",
   ]
   ```



-- 
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 #4327: fix bug: right semi join can't support the filter

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


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -2371,6 +2431,65 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn join_right_semi_with_filter() -> Result<()> {
+        let session_ctx = SessionContext::new();
+        let task_ctx = session_ctx.task_ctx();
+        let left = build_table(
+            ("a2", &vec![10, 20, 30, 40]),
+            ("b2", &vec![4, 5, 6, 5]), // 5 is double on the left
+            ("c2", &vec![70, 80, 90, 100]),
+        );
+        let right = build_table(
+            ("a1", &vec![1, 2, 2, 3]),
+            ("b1", &vec![4, 5, 5, 7]), // 7 does not exist on the left
+            ("c1", &vec![7, 8, 8, 9]),
+        );
+
+        let on = vec![(
+            Column::new_with_schema("b2", &left.schema())?,
+            Column::new_with_schema("b1", &right.schema())?,
+        )];
+
+        // build filter left.b2 > 4
+        let column_indices = vec![ColumnIndex {
+            index: 1,
+            side: JoinSide::Left,
+        }];
+        let intermediate_schema =
+            Schema::new(vec![Field::new("x", DataType::Int32, true)]);
+
+        let filter_expression = Arc::new(BinaryExpr::new(
+            Arc::new(Column::new("x", 0)),
+            Operator::Gt,
+            Arc::new(Literal::new(ScalarValue::Int32(Some(4)))),
+        )) as Arc<dyn PhysicalExpr>;
+
+        let filter =
+            JoinFilter::new(filter_expression, column_indices, intermediate_schema);
+
+        let join =
+            join_with_filter(left, right, on, filter, &JoinType::RightSemi, false)?;
+
+        let columns = columns(&join.schema());
+        assert_eq!(columns, vec!["a1", "b1", "c1"]);
+
+        let stream = join.execute(0, task_ctx)?;
+        let batches = common::collect(stream).await?;
+
+        let expected = vec![

Review Comment:
   If don't fix this bug, the result will be
   ```
   [
       "+----+----+----+",
       "| a1 | b1 | c1 |",
       "+----+----+----+",
       "+----+----+----+",
   ]
   ```



-- 
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 #4327: fix bug: right semi join can't support the filter

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

   This bug is caused by this commit https://github.com/apache/arrow-datafusion/commit/d6f0b1261159f6f97cb14357489d9081e8bbd7ab#r90728800


-- 
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] alamb merged pull request #4327: fix bug: right semi join can't support the filter

Posted by GitBox <gi...@apache.org>.
alamb merged PR #4327:
URL: https://github.com/apache/arrow-datafusion/pull/4327


-- 
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 #4327: fix bug: right semi join can't support the filter

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

   > Thanks @liukun4515 and @Dandandan
   After I go through the code of `HashJoin`,  I was inspired by the thought in that, but find some point which need to be improved. 
   The refactor will help to fix the bug of `right anti` with filter.


-- 
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] alamb commented on a diff in pull request #4327: fix bug: right semi join can't support the filter

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


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -2329,6 +2332,63 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn join_left_semi_with_filter() -> Result<()> {
+        let session_ctx = SessionContext::new();
+        let task_ctx = session_ctx.task_ctx();
+        let left = build_table(
+            ("a1", &vec![1, 2, 2, 3]),
+            ("b1", &vec![4, 5, 5, 7]), // 7 does not exist on the right
+            ("c1", &vec![7, 8, 8, 9]),
+        );
+        let right = build_table(
+            ("a2", &vec![10, 20, 30, 40]),
+            ("b1", &vec![4, 5, 6, 5]), // 5 is double on the right
+            ("c2", &vec![70, 80, 90, 100]),
+        );
+        let on = vec![(
+            Column::new_with_schema("b1", &left.schema())?,
+            Column::new_with_schema("b1", &right.schema())?,
+        )];
+
+        // build filter right.b2 > 4

Review Comment:
   Ah, the key is this filter. 👍 



-- 
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 #4327: fix bug: right semi join can't support the filter

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


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -2329,6 +2332,63 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn join_left_semi_with_filter() -> Result<()> {

Review Comment:
   add test cases to ensure `left semi` with filter is correct.



-- 
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] ursabot commented on pull request #4327: fix bug: right semi join can't support the filter

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

   Benchmark runs are scheduled for baseline = 94cd98208af4433fd992ac3b7b738db98f791635 and contender = 92325bf167c0d215564695717cb56d01448887c8. 92325bf167c0d215564695717cb56d01448887c8 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/d978cee5108440cd869fd7c5ef328b40...0ff8445206304873957930456639c712/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/1e6a5c4966c748dea76773e802e62487...381b9593a1124abaa419a30ed11595ec/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/59d988bbf97c4d73a40fcb349b408d48...6d82de1dbc974726867152c7eacab666/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/997be33ea699420490419a2816bc096a...a6ba07860c2a4eecad52794d4d7e9429/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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 #4327: fix bug: right semi join can't support the filter

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


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -2329,6 +2332,63 @@ mod tests {
         Ok(())
     }
 
+    #[tokio::test]
+    async fn join_left_semi_with_filter() -> Result<()> {
+        let session_ctx = SessionContext::new();
+        let task_ctx = session_ctx.task_ctx();
+        let left = build_table(
+            ("a1", &vec![1, 2, 2, 3]),
+            ("b1", &vec![4, 5, 5, 7]), // 7 does not exist on the right
+            ("c1", &vec![7, 8, 8, 9]),
+        );
+        let right = build_table(
+            ("a2", &vec![10, 20, 30, 40]),
+            ("b1", &vec![4, 5, 6, 5]), // 5 is double on the right
+            ("c2", &vec![70, 80, 90, 100]),
+        );
+        let on = vec![(
+            Column::new_with_schema("b1", &left.schema())?,
+            Column::new_with_schema("b1", &right.schema())?,
+        )];
+
+        // build filter right.b2 > 4

Review Comment:
   > Ah, the key is this filter. 👍
   
   Yes, we can add `filter` to filter left row or right row, and get the new result.
   



-- 
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 #4327: fix bug: right semi join can't support the filter

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


##########
datafusion/core/src/physical_plan/joins/hash_join.rs:
##########
@@ -852,6 +852,7 @@ fn build_join_indexes(
                             &keys_values,
                             *null_equals_null,
                         )? {
+                            left_indices.append(i);

Review Comment:
   Ah good find. I missed the case where this would be used.
   Thanks for adding the unit test!



-- 
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 #4327: fix bug: right semi join can't support the filter

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

   find a new bug for the `right semi` join again for `break` line https://github.com/liukun4515/arrow-datafusion/blob/d884bb50a312b7fb01d6e3ffd204919100ae3893/datafusion/core/src/physical_plan/joins/hash_join.rs#L857
   
   for example
   ```
   left 
   a  b
   1   2
   1   3
   2  4
   ```
   
   ```
   right
   a
   1
   ```
   with sql
   ```
   left  `right semi` join right on left.a=right.a and left.b!=2
   ```
   
   In the current code, we will get the empty result because of break in the `first match`
   


-- 
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 pull request #4327: fix bug: right semi join can't support the filter

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

   Yes, it is a bug indeed.


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