use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class Memo method replace.
public PlanNode replace(int group, PlanNode node, String reason) {
PlanNode old = membership.get(group);
checkArgument(new HashSet<>(old.getOutputSymbols()).equals(new HashSet<>(node.getOutputSymbols())), "%s: transformed expression doesn't produce same outputs: %s vs %s", reason, old.getOutputSymbols(), node.getOutputSymbols());
if (node instanceof GroupReference) {
node = getNode(((GroupReference) node).getGroupId());
} else {
node = insertChildrenAndRewrite(node);
}
incrementReferenceCounts(node);
membership.put(group, node);
decrementReferenceCounts(old);
return node;
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class Memo method insertRecursive.
private int insertRecursive(PlanNode node) {
if (node instanceof GroupReference) {
return ((GroupReference) node).getGroupId();
}
int group = nextGroupId();
PlanNode rewritten = insertChildrenAndRewrite(node);
membership.put(group, rewritten);
referenceCounts.put(group, 0);
incrementReferenceCounts(rewritten);
return group;
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class MergeLimitWithDistinct method apply.
@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
if (!(node instanceof LimitNode)) {
return Optional.empty();
}
LimitNode parent = (LimitNode) node;
PlanNode input = lookup.resolve(parent.getSource());
if (!(input instanceof AggregationNode)) {
return Optional.empty();
}
AggregationNode child = (AggregationNode) input;
if (isDistinct(child)) {
return Optional.empty();
}
return Optional.of(new DistinctLimitNode(parent.getId(), child.getSource(), parent.getCount(), false, child.getHashSymbol()));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class MergeLimitWithSort method apply.
@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
if (!(node instanceof LimitNode)) {
return Optional.empty();
}
LimitNode parent = (LimitNode) node;
PlanNode source = lookup.resolve(parent.getSource());
if (!(source instanceof SortNode)) {
return Optional.empty();
}
SortNode child = (SortNode) source;
return Optional.of(new TopNNode(parent.getId(), child.getSource(), parent.getCount(), child.getOrderBy(), child.getOrderings(), parent.isPartial()));
}
use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.
the class MergeLimitWithTopN method apply.
@Override
public Optional<PlanNode> apply(PlanNode node, Lookup lookup, PlanNodeIdAllocator idAllocator, SymbolAllocator symbolAllocator) {
if (!(node instanceof LimitNode)) {
return Optional.empty();
}
LimitNode parent = (LimitNode) node;
PlanNode source = lookup.resolve(parent.getSource());
if (!(source instanceof TopNNode)) {
return Optional.empty();
}
TopNNode child = (TopNNode) source;
return Optional.of(new TopNNode(parent.getId(), child.getSource(), Math.min(parent.getCount(), child.getCount()), child.getOrderBy(), child.getOrderings(), parent.isPartial()));
}
Aggregations