Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include all Right Table Values in Match Column #5190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.deephaven.api.Selectable;
import io.deephaven.api.TableOperationsDefaults;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.impl.CrossJoinHelper;
Expand All @@ -24,7 +23,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -96,17 +94,17 @@ public static Table fullOuterJoin(
? Arrays.stream(columnsToAdd).map(mp -> new SourceColumn(mp.rightColumn(), mp.leftColumn()))
: table2.getDefinition().getColumnNames().stream().map(SourceColumn::new);

// we merge identity match columns, otherwise all left columns are to be null view columns
final Set<String> identityMatchColumns = Arrays.stream(columnsToMatch)
.filter(mp -> mp.leftColumn().equals(mp.rightColumn()))
// we merge match columns, otherwise all left columns are to be null view columns
final Set<String> matchColumns = Arrays.stream(columnsToMatch)
.map(MatchPair::leftColumn)
.collect(Collectors.toSet());

// note that right sourced columns must be applied first to avoid any clashing column names
final List<SelectColumn> rightColumns = Streams.concat(
identityMatchColumns.stream().map(SourceColumn::new), rightSourcedColumns,
rightSourcedColumns,
Arrays.stream(columnsToMatch).map(mp -> new SourceColumn(mp.rightColumn(), mp.leftColumn())),
table1.getColumnSourceMap().entrySet().stream()
.filter(entry -> !identityMatchColumns.contains(entry.getKey()))
.filter(entry -> !matchColumns.contains(entry.getKey()))
.map(entry -> new NullSelectColumn<>(
entry.getValue().getType(), entry.getValue().getComponentType(), entry.getKey())))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testFullOuterJoin() {
assertEquals(2, DataAccessHelpers.getColumns(result).length);
assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName());
assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName());
assertEquals(Arrays.asList("a", "b", "c", null),
assertEquals(Arrays.asList("a", "b", "c", "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4)));
assertEquals(Arrays.asList("a", "b", null, "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4)));
Expand All @@ -145,7 +145,7 @@ public void testFullOuterJoin() {
assertEquals(2, DataAccessHelpers.getColumns(result).length);
assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName());
assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName());
assertEquals(Arrays.asList("a", "b", "c", null),
assertEquals(Arrays.asList("a", "b", "c", "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4)));
assertEquals(Arrays.asList("a", "b", null, "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4)));
Expand Down Expand Up @@ -175,15 +175,15 @@ public void testFullOuterJoin() {
}

@Test
public void testFullOuterJoinAddColumnsDoesNotIncludeRightMatchColumns() {
public void testFullOuterJoinAddColumnsDoesIncludeRightMatchColumns() {
Table lTable = testRefreshingTable(col("X", "a", "b", "c"));
Table rTable = testRefreshingTable(col("Y", "a", "b", "d"), intCol("Z", 1, 2, 3));
Table result = OuterJoinTools.fullOuterJoin(lTable, rTable, "X=Y", "A=Y");
assertEquals(4, result.size());
assertEquals(2, DataAccessHelpers.getColumns(result).length);
assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName());
assertEquals("A", DataAccessHelpers.getColumns(result)[1].getName());
assertEquals(Arrays.asList("a", "b", "c", null),
assertEquals(Arrays.asList("a", "b", "c", "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4)));
assertEquals(Arrays.asList("a", "b", null, "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "A").get(0, 4)));
Expand All @@ -198,7 +198,7 @@ public void testFullOuterJoinAddColumnRenamesToOverrideMatchColumnName() {
assertEquals(2, DataAccessHelpers.getColumns(result).length);
assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName());
assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName());
assertEquals(Arrays.asList("a", "b", "c", null),
assertEquals(Arrays.asList("a", "b", "c", "g"),
Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 4)));
assertEquals(Arrays.asList("e", "f", null, "g"),
Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 4)));
Expand All @@ -216,7 +216,7 @@ public void testFullOuterJoinMultipleMatchesBothSides() {
assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName());
assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName());
assertEquals("Z", DataAccessHelpers.getColumns(result)[2].getName());
assertEquals(Arrays.asList("a", "a", "b", "b", "c", null),
assertEquals(Arrays.asList("a", "a", "b", "b", "c", "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 6)));
assertEquals(Arrays.asList("a", "a", "b", "b", null, "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 6)));
Expand All @@ -233,7 +233,7 @@ public void testFullOuterJoinMultipleMatchesBothSides() {
assertEquals(2, DataAccessHelpers.getColumns(result).length);
assertEquals("X", DataAccessHelpers.getColumns(result)[0].getName());
assertEquals("Y", DataAccessHelpers.getColumns(result)[1].getName());
assertEquals(Arrays.asList("a", "a", "b", "b", "c", null),
assertEquals(Arrays.asList("a", "a", "b", "b", "c", "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "X").get(0, 6)));
assertEquals(Arrays.asList("a", "a", "b", "b", null, "d"),
Arrays.asList(DataAccessHelpers.getColumn(result, "Y").get(0, 6)));
Expand Down
Loading