Class MultiJoinFactory
Join unique rows from a set of tables onto a set of common keys.
The multiJoin operation collects the set of distinct keys from the input tables, then joins at most one row per key from each of the input tables onto the result. Input tables need not have a matching row for each key, but they may not have multiple matching rows for a given key.
Input tables with non-matching key column names must use the JoinMatch
format to map keys to the common
output table key column names (e.g. "OutputKey=SourceKey"). Also, individual columns to include from input tables may
be specified and optionally renamed using JoinAddition
format (e.g. "NewCol=OldColName"). If
no output columns are specified then every non-key column from the input table will be included in the multi-join
output table.
The multiJoin operation can be thought of as a merge of the key columns, followed by a selectDistinct and then a series of iterative naturalJoin operations as follows (this example has common key column names and includes all columns from the input tables):
private Table doIterativeMultiJoin(String [] keyColumns, List<? extends Table> inputTables) {
final List<Table> keyTables = inputTables.stream().map(t -> t.view(keyColumns)).collect(Collectors.toList());
final Table base = TableTools.merge(keyTables).selectDistinct(keyColumns);
Table result = base;
for (int ii = 0; ii < inputTables.size(); ++ii) {
result = result.naturalJoin(inputTables.get(ii), Arrays.asList(keyColumns));
}
return result;
}
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Creator interface for runtime-supplied implementation.static interface
Creator provider to supply the implementation at runtime. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MultiJoinTable
of
(@NotNull MultiJoinInput... multiJoinInputs) Perform a multiJoin for one or more tables; allows renaming of key column names and specifying individual input table columns to include in the final output table.static MultiJoinTable
Join tables that have common key column names; include all columns from the input tables.static MultiJoinTable
Join tables that have common key column names; include all columns from the input tables.
-
Constructor Details
-
MultiJoinFactory
public MultiJoinFactory()
-
-
Method Details
-
of
public static MultiJoinTable of(@NotNull @NotNull String[] keys, @NotNull @NotNull Table... inputTables) Join tables that have common key column names; include all columns from the input tables.- Parameters:
keys
- the key column pairs in the format "Result=Source" or "ColumnInBoth"inputTables
- the tables to join together- Returns:
- a MultiJoinTable with one row for each key and the corresponding row in each input table
-
of
public static MultiJoinTable of(@NotNull @NotNull String columnsToMatch, @NotNull @NotNull Table... inputTables) Join tables that have common key column names; include all columns from the input tables.- Parameters:
columnsToMatch
- A comma separated list of key columns, in string format (e.g. "ResultKey=SourceKey" or "KeyInBoth").inputTables
- the tables to join together- Returns:
- a MultiJoinTable with one row for each key and the corresponding row in each input table
-
of
Perform a multiJoin for one or more tables; allows renaming of key column names and specifying individual input table columns to include in the final output table.- Parameters:
multiJoinInputs
- the description of each table that contributes to the result- Returns:
- a MultiJoinTable with one row for each key and the corresponding row in each input table
-