Skip to content

Commit

Permalink
FullOuterJoin Fix Missing Match Columns From Right (#3386)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbauernfeind authored Jan 31, 2023
1 parent 663f093 commit 2b6170a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public static Table fullOuterJoin(
.collect(Collectors.toSet());

// note that right sourced columns must be applied first to avoid any clashing column names
final SelectColumn[] rightColumns = Streams.concat(rightSourcedColumns,
final SelectColumn[] rightColumns = Streams.concat(
identityMatchColumns.stream().map(SourceColumn::new), rightSourcedColumns,
table1.getColumnSourceMap().entrySet().stream()
.filter(entry -> !identityMatchColumns.contains(entry.getKey()))
.map(entry -> new NullSelectColumn<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,20 @@ public void testFullOuterJoinMultipleMatchesBothSides() {
assertEquals(Arrays.asList("a", "a", "b", "b", "c", null), Arrays.asList(result.getColumn("X").get(0, 6)));
assertEquals(Arrays.asList("a", "a", "b", "b", null, "d"), Arrays.asList(result.getColumn("Y").get(0, 6)));
}

@Test
public void testFullOuterJoinIdentityMatchWithAddColumn() {
Table lTable = TableTools.emptyTable(4).update("a = i", "b = i * 2");
Table rTable = TableTools.emptyTable(4).update("a = i", "c = i * 3");
Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "a", "c");

assertEquals(4, result.size());
assertEquals(3, result.getColumns().length);
assertEquals("a", result.getColumns()[0].getName());
assertEquals("b", result.getColumns()[1].getName());
assertEquals("c", result.getColumns()[2].getName());
assertEquals(Arrays.asList(0, 1, 2, 3), Arrays.asList(result.getColumn("a").get(0, 9)));
assertEquals(Arrays.asList(0, 2, 4, 6), Arrays.asList(result.getColumn("b").get(0, 9)));
assertEquals(Arrays.asList(0, 3, 6, 9), Arrays.asList(result.getColumn("c").get(0, 9)));
}
}

0 comments on commit 2b6170a

Please sign in to comment.