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

Use putIdentity method to reduce code duplication #18326

Merged
merged 1 commit into from
Jul 20, 2023
Merged
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 @@ -547,7 +547,7 @@ public PlanNode plan(Delete node)
Symbol symbol = relationPlan.getFieldMappings().get(fieldIndex);
columnSymbolsBuilder.add(symbol);
if (mergeAnalysis.getRedistributionColumnHandles().contains(columnHandle)) {
assignmentsBuilder.put(symbol, symbol.toSymbolReference());
assignmentsBuilder.putIdentity(symbol);
}
else {
assignmentsBuilder.put(symbol, new NullLiteral());
Expand Down Expand Up @@ -720,11 +720,11 @@ public PlanNode plan(Update node)
for (ColumnHandle column : mergeAnalysis.getRedistributionColumnHandles()) {
int fieldIndex = requireNonNull(mergeAnalysis.getColumnHandleFieldNumbers().get(column), "Could not find fieldIndex for redistribution column");
Symbol symbol = relationPlan.getFieldMappings().get(fieldIndex);
projectionAssignmentsBuilder.put(symbol, symbol.toSymbolReference());
projectionAssignmentsBuilder.putIdentity(symbol);
}

// Add the rest of the page columns: rowId, merge row, case number and is_distinct
projectionAssignmentsBuilder.put(rowIdSymbol, rowIdSymbol.toSymbolReference());
projectionAssignmentsBuilder.putIdentity(rowIdSymbol);
projectionAssignmentsBuilder.put(mergeRowSymbol, mergeRow);
projectionAssignmentsBuilder.put(caseNumberSymbol, new GenericLiteral("INTEGER", "0"));
projectionAssignmentsBuilder.put(isDistinctSymbol, TRUE_LITERAL);
Expand Down Expand Up @@ -858,10 +858,10 @@ public MergeWriterNode plan(Merge merge)
for (ColumnHandle column : mergeAnalysis.getRedistributionColumnHandles()) {
int fieldIndex = requireNonNull(mergeAnalysis.getColumnHandleFieldNumbers().get(column), "Could not find fieldIndex for redistribution column");
Symbol symbol = planWithPresentColumn.getFieldMappings().get(fieldIndex);
projectionAssignmentsBuilder.put(symbol, symbol.toSymbolReference());
projectionAssignmentsBuilder.putIdentity(symbol);
}
projectionAssignmentsBuilder.put(uniqueIdSymbol, uniqueIdSymbol.toSymbolReference());
projectionAssignmentsBuilder.put(rowIdSymbol, rowIdSymbol.toSymbolReference());
projectionAssignmentsBuilder.putIdentity(uniqueIdSymbol);
projectionAssignmentsBuilder.putIdentity(rowIdSymbol);
projectionAssignmentsBuilder.put(mergeRowSymbol, caseExpression);

ProjectNode subPlanProject = new ProjectNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,13 +975,13 @@ If casts are redundant (due to column type and common type being equal),
for (int field : joinAnalysis.getOtherLeftFields()) {
Symbol symbol = left.getFieldMappings().get(field);
outputs.add(symbol);
assignments.put(symbol, symbol.toSymbolReference());
assignments.putIdentity(symbol);
}

for (int field : joinAnalysis.getOtherRightFields()) {
Symbol symbol = right.getFieldMappings().get(field);
outputs.add(symbol);
assignments.put(symbol, symbol.toSymbolReference());
assignments.putIdentity(symbol);
}

return new RelationPlan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private Optional<PlanNode> coalesceWithNullAggregation(AggregationNode aggregati
assignmentsBuilder.put(symbol, new CoalesceExpression(symbol.toSymbolReference(), sourceAggregationToOverNullMapping.get(symbol).toSymbolReference()));
}
else {
assignmentsBuilder.put(symbol, symbol.toSymbolReference());
assignmentsBuilder.putIdentity(symbol);
}
}
return Optional.of(new ProjectNode(idAllocator.getNextId(), crossJoin, assignmentsBuilder.build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public Result apply(ProjectNode project, Captures captures, Context context)
partitioningColumns.stream()
.map(outputToInputMap::get)
.forEach(inputSymbol -> {
projections.put(inputSymbol, inputSymbol.toSymbolReference());
projections.putIdentity(inputSymbol);
inputs.add(inputSymbol);
});

// Need to retain the hash symbol for the exchange
exchange.getPartitioningScheme().getHashColumn()
.map(outputToInputMap::get)
.ifPresent(inputSymbol -> {
projections.put(inputSymbol, inputSymbol.toSymbolReference());
projections.putIdentity(inputSymbol);
inputs.add(inputSymbol);
});

Expand All @@ -116,7 +116,7 @@ public Result apply(ProjectNode project, Captures captures, Context context)
.filter(symbol -> !partitioningColumns.contains(symbol))
.map(outputToInputMap::get)
.forEach(inputSymbol -> {
projections.put(inputSymbol, inputSymbol.toSymbolReference());
projections.putIdentity(inputSymbol);
inputs.add(inputSymbol);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ private PlanWithProperties enforce(PlanWithProperties planWithProperties, HashCo
for (Symbol symbol : planWithProperties.getNode().getOutputSymbols()) {
HashComputation partitionSymbols = resultHashSymbols.get(symbol);
if (partitionSymbols == null || requiredHashes.getHashes().contains(partitionSymbols)) {
assignments.put(symbol, symbol.toSymbolReference());
assignments.putIdentity(symbol);

if (partitionSymbols != null) {
outputHashSymbols.put(partitionSymbols, symbol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public void testDoesNotFireNarrowingProjection()

return p.project(
Assignments.builder()
.put(a, a.toSymbolReference())
.put(b, b.toSymbolReference())
.putIdentity(a)
.putIdentity(b)
.build(),
p.exchange(e -> e
.addSource(p.values(a, b, c))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void testPushTopNThroughOverlappingDereferences()
Assignments.builder()
.put(p.symbol("b"), new SubscriptExpression(a.toSymbolReference(), new LongLiteral("1")))
.put(p.symbol("c", rowType), a.toSymbolReference())
.put(d, d.toSymbolReference())
.putIdentity(d)
.build(),
p.values(a, d)));
})
Expand Down