Skip to content
Closed
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 @@ -415,6 +415,7 @@ private RelationPlan planJoinUsing(Join node, RelationPlan left, RelationPlan ri

If casts are redundant (due to column type and common type being equal),
they will be removed by optimization passes.
Coalesce will be added only in case of full joins.
*/

List<Identifier> joinColumns = ((JoinUsing) node.getCriteria().get()).getColumns();
Expand Down Expand Up @@ -477,16 +478,32 @@ If casts are redundant (due to column type and common type being equal),
Optional.empty());

// Add a projection to produce the outputs of the columns in the USING clause,
// which are defined as coalesce(l.k, r.k)
// which are defined as
// For Left and Inner Join l.k
// For Right Join r.k
// For Full join coalesce(l.k, r.k)
Assignments.Builder assignments = Assignments.builder();

ImmutableList.Builder<Symbol> outputs = ImmutableList.builder();
for (Identifier column : joinColumns) {
Symbol output = symbolAllocator.newSymbol(column, analysis.getType(column));
outputs.add(output);
assignments.put(output, new CoalesceExpression(
leftJoinColumns.get(column).toSymbolReference(),
rightJoinColumns.get(column).toSymbolReference()));
switch (join.getType()) {
case LEFT:
case INNER:
assignments.put(output, leftJoinColumns.get(column).toSymbolReference());
break;
case RIGHT:
assignments.put(output, rightJoinColumns.get(column).toSymbolReference());
break;
case FULL:
assignments.put(output, new CoalesceExpression(
leftJoinColumns.get(column).toSymbolReference(),
rightJoinColumns.get(column).toSymbolReference()));
break;
default:
throw new UnsupportedOperationException("Unsupported join type: " + node.getType());
}
}

for (int field : joinAnalysis.getOtherLeftFields()) {
Expand Down