alamb commented on a change in pull request #291: URL: https://github.com/apache/arrow-datafusion/pull/291#discussion_r628874887
########## File path: datafusion/src/physical_plan/hash_join.rs ########## @@ -1515,6 +1589,43 @@ mod tests { Ok(()) } + #[tokio::test] + async fn join_outer_one() -> Result<()> { + let left = build_table( + ("a1", &vec![1, 2, 3]), + ("b1", &vec![4, 5, 7]), // 7 does not exist on the right + ("c1", &vec![7, 8, 9]), + ); + let right = build_table( + ("a2", &vec![10, 20, 30]), + ("b1", &vec![4, 5, 6]), + ("c2", &vec![70, 80, 90]), + ); + let on = &[("b1", "b1")]; + + let join = join(left, right, on, &JoinType::Full)?; + + let columns = columns(&join.schema()); + assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "c2"]); + + let stream = join.execute(0).await?; + let batches = common::collect(stream).await?; + + let expected = vec![ + "+----+----+----+----+----+", + "| a1 | b1 | c1 | a2 | c2 |", + "+----+----+----+----+----+", + "| | | | 30 | 90 |", Review comment: this row should also have `b1=6` I think ########## File path: ballista/rust/core/src/serde/physical_plan/to_proto.rs ########## @@ -132,6 +132,7 @@ impl TryInto<protobuf::PhysicalPlanNode> for Arc<dyn ExecutionPlan> { JoinType::Inner => protobuf::JoinType::Inner, JoinType::Left => protobuf::JoinType::Left, JoinType::Right => protobuf::JoinType::Right, + JoinType::Full => protobuf::JoinType::Right, Review comment: This looks like it is a typo perhaps ```suggestion JoinType::Full => protobuf::JoinType::Full, ``` ########## File path: datafusion/src/physical_plan/hash_join.rs ########## @@ -1410,6 +1413,45 @@ mod tests { assert_batches_sorted_eq!(expected, &batches); } + #[tokio::test] + async fn join_outer_multi_batch() { + let left = build_table( + ("a1", &vec![1, 2, 3]), + ("b1", &vec![4, 5, 7]), // 7 does not exist on the right + ("c1", &vec![7, 8, 9]), + ); + let right = build_table_two_batches( + ("a2", &vec![10, 20, 30]), + ("b1", &vec![4, 5, 6]), + ("c2", &vec![70, 80, 90]), + ); + let on = &[("b1", "b1")]; + + let join = join(left, right, on, &JoinType::Full).unwrap(); + + let columns = columns(&join.schema()); + assert_eq!(columns, vec!["a1", "b1", "c1", "a2", "c2"]); + + let stream = join.execute(0).await.unwrap(); + let batches = common::collect(stream).await.unwrap(); + + let expected = vec![ Review comment: This doesn't look like the correct answer to me. FULL OUTER JOIN basically keeps tuples from boths sides that don't match the join criteria. So we should have 2 rows for `b1=4' and `b1=5` and then 1 row for tuple on the left that has no match with the right, `b1=7` and 1 row for the tuple on the right that has no match with the left `b1=6` And indeed postgres returns 4 rows as well ``` alamb=# select * from tleft; a1 | b1 | c1 ----+----+---- 1 | 4 | 7 2 | 5 | 8 3 | 7 | 9 (3 rows) alamb=# select * from tright; a2 | b2 | c2 ----+----+---- 10 | 4 | 70 2 | 5 | 80 3 | 6 | 90 (3 rows) alamb=# select * from tleft FULL JOIN tright ON (tleft.b1 = tright.b2); a1 | b1 | c1 | a2 | b2 | c2 ----+----+----+----+----+---- 1 | 4 | 7 | 10 | 4 | 70 2 | 5 | 8 | 2 | 5 | 80 | | | 3 | 6 | 90 3 | 7 | 9 | | | (4 rows) ``` -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org