Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CachingCostProvider
private final Optional<Memo> memo;
private final Session session;

private final Map<PlanNode, PlanCostEstimate> cache = new IdentityHashMap<>();
private final Map<PlanNode, PlanCostEstimate> cache = new IdentityHashMap<>(0);

public CachingCostProvider(CostCalculator costCalculator, StatsProvider statsProvider, Session session)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class CachingStatsProvider
private final TableStatsProvider tableStatsProvider;
private final RuntimeInfoProvider runtimeInfoProvider;

private final Map<PlanNode, PlanNodeStatsEstimate> cache = new IdentityHashMap<>();
private final Map<PlanNode, PlanNodeStatsEstimate> cache = new IdentityHashMap<>(0);

public CachingStatsProvider(StatsCalculator statsCalculator, Session session, TableStatsProvider tableStatsProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public Void visitFilter(FilterNode node, Void context)
@Override
public Void visitProject(ProjectNode node, Void context)
{
node.getAssignments().getExpressions().forEach(consumer);
node.getAssignments().expressions().forEach(consumer);
return super.visitProject(node, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ private PlanBuilder planAggregation(PlanBuilder subPlan, List<List<Symbol>> grou
}
}

ImmutableList.Builder<Symbol> groupingKeys = ImmutableList.builder();
ImmutableSet.Builder<Symbol> groupingKeys = ImmutableSet.builder();
groupingSets.stream()
.flatMap(List::stream)
.distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ private boolean exploreNode(int group, Context context, Set<PlanNodeId> changedP
invoked = true;
Rule.Result result = transform(node, rule, context);
timeEnd = nanoTime();
if (result.getTransformedPlan().isPresent()) {
changedPlanNodeIds.add(result.getTransformedPlan().get().getId());
}
if (result.getTransformedPlan().isPresent()) {
node = context.memo.replace(group, result.getTransformedPlan().get(), rule.getClass().getName());
if (result.isPresent()) {
changedPlanNodeIds.add(result.transformedPlan().get().getId());
node = context.memo.replace(group, result.transformedPlan().get(), rule.getClass().getName());

applied = true;
done = false;
Expand Down Expand Up @@ -226,7 +224,7 @@ private <T> Rule.Result transform(PlanNode node, Rule<T> rule, Context context)
0,
false),
PlanPrinter.textLogicalPlan(
result.getTransformedPlan().get(),
result.transformedPlan().get(),
plannerContext.getMetadata(),
plannerContext.getFunctionManager(),
StatsAndCosts.empty(),
Expand All @@ -243,7 +241,7 @@ private <T> Rule.Result transform(PlanNode node, Rule<T> rule, Context context)
}
stats.record(rule, duration, !result.isEmpty());

if (result.getTransformedPlan().isPresent()) {
if (result.isPresent()) {
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface Context
WarningCollector getWarningCollector();
}

final class Result
record Result(Optional<PlanNode> transformedPlan)
{
private static final Result EMPTY = new Result(Optional.empty());

Expand All @@ -74,21 +74,19 @@ public static Result ofPlanNode(PlanNode transformedPlan)
return new Result(Optional.of(transformedPlan));
}

private final Optional<PlanNode> transformedPlan;

private Result(Optional<PlanNode> transformedPlan)
public Result
{
this.transformedPlan = requireNonNull(transformedPlan, "transformedPlan is null");
requireNonNull(transformedPlan, "transformedPlan is null");
}

public Optional<PlanNode> getTransformedPlan()
public boolean isEmpty()
{
return transformedPlan;
return transformedPlan.isEmpty();
}

public boolean isEmpty()
public boolean isPresent()
{
return transformedPlan.isEmpty();
return transformedPlan.isPresent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private static boolean isSupportedUnnest(PlanNode node, List<Symbol> correlation
PlanNode unnestSource = lookup.resolve(unnestNode.getSource());
Set<Symbol> correlationSymbols = ImmutableSet.copyOf(correlation);
boolean basedOnCorrelation = correlationSymbols.containsAll(unnestSymbols) ||
unnestSource instanceof ProjectNode projectNode && correlationSymbols.containsAll(SymbolsExtractor.extractUnique(projectNode.getAssignments().getExpressions()));
unnestSource instanceof ProjectNode projectNode && correlationSymbols.containsAll(SymbolsExtractor.extractUnique(projectNode.getAssignments().expressions()));

return isScalar(unnestNode.getSource(), lookup) &&
unnestNode.getReplicateSymbols().isEmpty() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static boolean isSupportedUnnest(PlanNode node, List<Symbol> correlation
.collect(toImmutableList());
PlanNode unnestSource = lookup.resolve(unnestNode.getSource());
boolean basedOnCorrelation = ImmutableSet.copyOf(correlation).containsAll(unnestSymbols) ||
unnestSource instanceof ProjectNode projectNode && ImmutableSet.copyOf(correlation).containsAll(SymbolsExtractor.extractUnique(projectNode.getAssignments().getExpressions()));
unnestSource instanceof ProjectNode projectNode && ImmutableSet.copyOf(correlation).containsAll(SymbolsExtractor.extractUnique(projectNode.getAssignments().expressions()));

return isScalar(unnestNode.getSource(), lookup) &&
unnestNode.getReplicateSymbols().isEmpty() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private static boolean isSupportedUnnest(PlanNode node, List<Symbol> correlation
.collect(toImmutableList());
PlanNode unnestSource = lookup.resolve(unnestNode.getSource());
boolean basedOnCorrelation = ImmutableSet.copyOf(correlation).containsAll(unnestSymbols) ||
unnestSource instanceof ProjectNode projectNode && ImmutableSet.copyOf(correlation).containsAll(SymbolsExtractor.extractUnique(projectNode.getAssignments().getExpressions()));
unnestSource instanceof ProjectNode projectNode && ImmutableSet.copyOf(correlation).containsAll(SymbolsExtractor.extractUnique(projectNode.getAssignments().expressions()));

return isScalar(unnestNode.getSource(), lookup) &&
unnestNode.getReplicateSymbols().isEmpty() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Result apply(FilterNode node, Captures captures, Context context)
}

Assignments assignments = Assignments.of(dereferences, context.getSymbolAllocator());
Map<Expression, Reference> mappings = HashBiMap.create(assignments.getMap())
Map<Expression, Reference> mappings = HashBiMap.create(assignments.assignments())
.inverse()
.entrySet().stream()
.collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected static Optional<WindowNode> pullWindowNodeAboveProjects(
// The only kind of use of the output of the target that we can safely ignore is a simple identity propagation.
// The target node, when hoisted above the projections, will provide the symbols directly.
Map<Symbol, Expression> assignmentsWithoutTargetOutputIdentities = Maps.filterKeys(
project.getAssignments().getMap(),
project.getAssignments().assignments(),
output -> !(project.getAssignments().isIdentity(output) && targetOutputs.contains(output)));

if (targetInputs.stream().anyMatch(assignmentsWithoutTargetOutputIdentities::containsKey)) {
Expand All @@ -152,7 +152,7 @@ protected static Optional<WindowNode> pullWindowNodeAboveProjects(
.putIdentities(targetInputs)
.build();

if (!newTargetChildOutputs.containsAll(SymbolsExtractor.extractUnique(newAssignments.getExpressions()))) {
if (!newTargetChildOutputs.containsAll(SymbolsExtractor.extractUnique(newAssignments.expressions()))) {
// Projection uses an output of the target -- can't move the target above this projection.
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ public Result apply(FilterNode node, Captures captures, Context context)
return Result.empty();
}

Set<Symbol> postFilterSymbols = postFilterAssignments.getSymbols();
Set<Symbol> postFilterSymbols = postFilterAssignments.outputs();
// Remove inlined expressions from the underlying projection.
newAssignments.putAll(projectNode.getAssignments().filter(symbol -> !postFilterSymbols.contains(symbol)));

Map<Symbol, Expression> outputAssignments = new HashMap<>();
outputAssignments.putAll(Assignments.identity(node.getOutputSymbols()).getMap());
outputAssignments.putAll(Assignments.identity(node.getOutputSymbols()).assignments());
// Restore inlined symbols.
outputAssignments.putAll(postFilterAssignments.getMap());
outputAssignments.putAll(postFilterAssignments.assignments());

return Result.ofPlanNode(new ProjectNode(
context.getIdAllocator().getNextId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private static Set<Symbol> extractInliningTargets(ProjectNode parent, ProjectNod
Set<Symbol> childOutputSet = ImmutableSet.copyOf(child.getOutputSymbols());

Map<Symbol, Long> dependencies = parent.getAssignments()
.getExpressions().stream()
.expressions().stream()
.flatMap(expression -> SymbolsExtractor.extractAll(expression).stream())
.filter(childOutputSet::contains)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Result apply(PatternRecognitionNode node, Captures captures, Context cont
// put prerequisite assignments in the source of merged node,
// and the remaining assignments on top of merged node
Assignments remainingAssignments = project.getAssignments()
.filter(symbol -> !prerequisites.getSymbols().contains(symbol));
.filter(symbol -> !prerequisites.outputs().contains(symbol));

merged = (PatternRecognitionNode) merged.replaceChildren(ImmutableList.of(new ProjectNode(
context.getIdAllocator().getNextId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Optional<PlanNode> visitFilter(FilterNode node, Void context)
@Override
public Optional<PlanNode> visitProject(ProjectNode node, Void context)
{
boolean isDeterministic = node.getAssignments().getExpressions().stream()
boolean isDeterministic = node.getAssignments().expressions().stream()
.allMatch(DeterminismEvaluator::isDeterministic);
if (!isDeterministic) {
// non-deterministic projections could be used in downstream filters which could
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Result apply(AggregationNode aggregationNode, Captures captures, Context
context);
AggregationNode preAggregation = createPreAggregation(
preProjection,
preGroupingExpressions.getOutputs(),
preGroupingExpressions.outputs(),
preAggregations,
context);
Map<CaseAggregation, Symbol> newProjectionSymbols = getNewProjectionSymbols(aggregations, context);
Expand Down Expand Up @@ -247,7 +247,7 @@ private Map<CaseAggregation, Symbol> getNewProjectionSymbols(List<CaseAggregatio

private AggregationNode createPreAggregation(
PlanNode source,
List<Symbol> groupingKeys,
Set<Symbol> groupingKeys,
Map<PreAggregationKey, PreAggregation> preAggregations,
Context context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Result apply(ProjectNode parent, Captures captures, Context context)
{
N targetNode = captures.get(targetCapture);

return pruneInputs(targetNode.getOutputSymbols(), parent.getAssignments().getExpressions())
return pruneInputs(targetNode.getOutputSymbols(), parent.getAssignments().expressions())
.flatMap(prunedOutputs -> this.pushDownProjectOff(context, targetNode, prunedOutputs))
.map(newChild -> parent.replaceChildren(ImmutableList.of(newChild)))
.map(Result::ofPlanNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Result apply(ProjectNode node, Captures captures, Rule.Context context)

// Pushdown superset of dereference expressions from projections and filtering predicate
List<Expression> expressions = ImmutableList.<Expression>builder()
.addAll(node.getAssignments().getExpressions())
.addAll(node.getAssignments().expressions())
.add(filterNode.getPredicate())
.build();

Expand All @@ -90,7 +90,7 @@ public Result apply(ProjectNode node, Captures captures, Rule.Context context)
Assignments dereferenceAssignments = Assignments.of(dereferences, context.getSymbolAllocator());

// Rewrite project node assignments using new symbols for dereference expressions
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.getMap())
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.assignments())
.inverse()
.entrySet().stream()
.collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Result apply(ProjectNode projectNode, Captures captures, Context context)

// Consider dereferences in projections and join filter for pushdown
ImmutableList.Builder<Expression> expressionsBuilder = ImmutableList.builder();
expressionsBuilder.addAll(projectNode.getAssignments().getExpressions());
expressionsBuilder.addAll(projectNode.getAssignments().expressions());
joinNode.getFilter().ifPresent(expressionsBuilder::add);
Set<FieldReference> dereferences = extractRowSubscripts(expressionsBuilder.build(), false);

Expand All @@ -114,7 +114,7 @@ public Result apply(ProjectNode projectNode, Captures captures, Context context)
Assignments dereferenceAssignments = Assignments.of(dereferences, context.getSymbolAllocator());

// Rewrite project node assignments using new symbols for dereference expressions
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.getMap())
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.assignments())
.inverse()
.entrySet().stream()
.collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference()));
Expand Down Expand Up @@ -145,7 +145,7 @@ else if (joinNode.getRight().getOutputSymbols().contains(baseSymbol)) {
PlanNode rightNode = createProjectNodeIfRequired(joinNode.getRight(), rightAssignments, context.getIdAllocator());

// Prepare new output symbols for join node
List<Symbol> referredSymbolsInAssignments = newAssignments.getExpressions().stream()
List<Symbol> referredSymbolsInAssignments = newAssignments.expressions().stream()
.flatMap(expression -> extractAll(expression).stream())
.collect(toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Result apply(ProjectNode node, Captures captures, Context context)
ProjectNode child = captures.get(CHILD);

// Extract dereferences from project node assignments for pushdown
Set<FieldReference> dereferences = extractRowSubscripts(node.getAssignments().getExpressions(), false);
Set<FieldReference> dereferences = extractRowSubscripts(node.getAssignments().expressions(), false);

// Exclude dereferences on symbols being synthesized within child
dereferences = dereferences.stream()
Expand All @@ -81,7 +81,7 @@ public Result apply(ProjectNode node, Captures captures, Context context)
Assignments dereferenceAssignments = Assignments.of(dereferences, context.getSymbolAllocator());

// Rewrite project node assignments using new symbols for dereference expressions
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.getMap())
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.assignments())
.inverse()
.entrySet().stream()
.collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Result apply(ProjectNode projectNode, Captures captures, Context context)
SemiJoinNode semiJoinNode = captures.get(CHILD);

// Extract dereferences from project node assignments for pushdown
Set<FieldReference> dereferences = extractRowSubscripts(projectNode.getAssignments().getExpressions(), false);
Set<FieldReference> dereferences = extractRowSubscripts(projectNode.getAssignments().expressions(), false);

// All dereferences can be assumed on the symbols coming from source, since filteringSource output is not propagated,
// and semiJoinOutput is of type boolean. We exclude pushdown of dereferences on sourceJoinSymbol.
Expand All @@ -94,7 +94,7 @@ public Result apply(ProjectNode projectNode, Captures captures, Context context)
Assignments dereferenceAssignments = Assignments.of(dereferences, context.getSymbolAllocator());

// Rewrite project node assignments using new symbols for dereference expressions
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.getMap())
Map<Expression, Reference> mappings = HashBiMap.create(dereferenceAssignments.assignments())
.inverse()
.entrySet().stream()
.collect(toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().toSymbolReference()));
Expand Down
Loading