Java tutorial
/* * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.facebook.presto.sql.planner; import com.facebook.presto.sql.planner.plan.PlanFragmentId; import com.facebook.presto.sql.planner.plan.PlanNode; import com.facebook.presto.sql.planner.plan.PlanNodeId; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.util.ArrayList; import java.util.List; import java.util.Set; import static com.google.common.base.Predicates.in; public class SubPlanBuilder { private final PlanFragmentId id; private PlanNode root; private PlanNodeId partitionedSource; private List<SubPlan> children = new ArrayList<>(); private final SymbolAllocator allocator; public SubPlanBuilder(PlanFragmentId id, SymbolAllocator allocator, PlanNode root) { Preconditions.checkNotNull(id, "id is null"); Preconditions.checkNotNull(allocator, "allocator is null"); Preconditions.checkNotNull(root, "root is null"); this.allocator = allocator; this.id = id; this.root = root; } public PlanFragmentId getId() { return id; } public PlanNode getRoot() { return root; } public SubPlanBuilder setRoot(PlanNode root) { Preconditions.checkNotNull(root, "root is null"); this.root = root; return this; } public boolean isPartitioned() { return partitionedSource != null; } public PlanNodeId getPartitionedSource() { return partitionedSource; } public SubPlanBuilder setPartitionedSource(PlanNodeId partitionedSource) { this.partitionedSource = partitionedSource; return this; } public SubPlanBuilder setUnpartitionedSource() { this.partitionedSource = null; return this; } public List<SubPlan> getChildren() { return children; } public SubPlanBuilder setChildren(Iterable<SubPlan> children) { this.children = Lists.newArrayList(children); return this; } public SubPlanBuilder addChild(SubPlan child) { this.children.add(child); return this; } public SubPlan build() { Set<Symbol> dependencies = SymbolExtractor.extract(root); PlanFragment fragment = new PlanFragment(id, partitionedSource, Maps.filterKeys(allocator.getTypes(), in(dependencies)), root); return new SubPlan(fragment, children); } }