use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.
the class SplitFiltering method getFilterNode.
private static List<PlanNode> getFilterNode(SqlStageExecution stage) {
PlanFragment fragment = stage.getFragment();
PlanNode root = fragment.getRoot();
List<PlanNode> result = new LinkedList<>();
Queue<PlanNode> queue = new LinkedList<>();
queue.add(root);
while (!queue.isEmpty()) {
PlanNode node = queue.poll();
if (node instanceof FilterNode || node instanceof TableScanNode) {
result.add(node);
}
queue.addAll(node.getSources());
}
return result;
}
use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.
the class ImplementFilteredAggregations method apply.
@Override
public Result apply(AggregationNode aggregationNode, Captures captures, Context context) {
Assignments.Builder newAssignments = Assignments.builder();
ImmutableMap.Builder<Symbol, Aggregation> aggregations = ImmutableMap.builder();
ImmutableList.Builder<Expression> maskSymbols = ImmutableList.builder();
boolean aggregateWithoutFilterPresent = false;
for (Map.Entry<Symbol, Aggregation> entry : aggregationNode.getAggregations().entrySet()) {
Symbol output = entry.getKey();
// strip the filters
Aggregation aggregation = entry.getValue();
Optional<Symbol> mask = aggregation.getMask();
if (aggregation.getFilter().isPresent()) {
Symbol filter = aggregation.getFilter().get();
Symbol symbol = context.getSymbolAllocator().newSymbol(filter.getName(), BOOLEAN);
verify(!mask.isPresent(), "Expected aggregation without mask symbols, see Rule pattern");
newAssignments.put(symbol, castToRowExpression(toSymbolReference(filter)));
mask = Optional.of(symbol);
maskSymbols.add(toSymbolReference(symbol));
} else {
aggregateWithoutFilterPresent = true;
}
aggregations.put(output, new Aggregation(aggregation.getFunctionCall(), aggregation.getArguments(), aggregation.isDistinct(), Optional.empty(), aggregation.getOrderingScheme(), mask));
}
Expression predicate = TRUE_LITERAL;
if (!aggregationNode.hasNonEmptyGroupingSet() && !aggregateWithoutFilterPresent) {
predicate = combineDisjunctsWithDefault(maskSymbols.build(), TRUE_LITERAL);
}
// identity projection for all existing inputs
newAssignments.putAll(AssignmentUtils.identityAsSymbolReferences(aggregationNode.getSource().getOutputSymbols()));
return Result.ofPlanNode(new AggregationNode(context.getIdAllocator().getNextId(), new FilterNode(context.getIdAllocator().getNextId(), new ProjectNode(context.getIdAllocator().getNextId(), aggregationNode.getSource(), newAssignments.build()), castToRowExpression(predicate)), aggregations.build(), aggregationNode.getGroupingSets(), ImmutableList.of(), aggregationNode.getStep(), aggregationNode.getHashSymbol(), aggregationNode.getGroupIdSymbol(), aggregationNode.getAggregationType(), aggregationNode.getFinalizeSymbol()));
}
use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.
the class ImplementIntersectAsUnion method apply.
@Override
public Result apply(IntersectNode node, Captures captures, Context context) {
SetOperationNodeTranslator translator = new SetOperationNodeTranslator(metadata, context.getSymbolAllocator(), context.getIdAllocator());
SetOperationNodeTranslator.TranslationResult result = translator.makeSetContainmentPlan(node);
return Result.ofPlanNode(new ProjectNode(context.getIdAllocator().getNextId(), new FilterNode(context.getIdAllocator().getNextId(), result.getPlanNode(), castToRowExpression(and(result.getPresentExpressions()))), AssignmentUtils.identityAsSymbolReferences(node.getOutputSymbols())));
}
use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.
the class ImplementLimitWithTies method apply.
@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
PlanNode child = captures.get(CHILD);
Symbol rankSymbol = context.getSymbolAllocator().newSymbol("rank_num", BIGINT);
WindowNode.Frame frame = new WindowNode.Frame(WindowFrameType.RANGE, FrameBoundType.UNBOUNDED_PRECEDING, Optional.empty(), FrameBoundType.CURRENT_ROW, Optional.empty(), Optional.empty(), Optional.empty());
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
WindowNode.Function rankFunction = new WindowNode.Function(call(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "rank").toString(), functionHandle, BIGINT), ImmutableList.of(), frame);
WindowNode windowNode = new WindowNode(context.getIdAllocator().getNextId(), child, new WindowNode.Specification(ImmutableList.of(), parent.getTiesResolvingScheme()), ImmutableMap.of(rankSymbol, rankFunction), Optional.empty(), ImmutableSet.of(), 0);
FilterNode filterNode = new FilterNode(context.getIdAllocator().getNextId(), windowNode, castToRowExpression(new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN_OR_EQUAL, toSymbolReference(rankSymbol), new GenericLiteral("BIGINT", Long.toString(parent.getCount())))));
ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), filterNode, AssignmentUtils.identityAsSymbolReferences(parent.getOutputSymbols()));
return Result.ofPlanNode(projectNode);
}
use of io.prestosql.spi.plan.FilterNode in project hetu-core by openlookeng.
the class ImplementOffset method apply.
@Override
public Result apply(OffsetNode parent, Captures captures, Context context) {
Symbol rowNumberSymbol = context.getSymbolAllocator().newSymbol("row_number", BIGINT);
RowNumberNode rowNumberNode = new RowNumberNode(context.getIdAllocator().getNextId(), parent.getSource(), ImmutableList.of(), rowNumberSymbol, Optional.empty(), Optional.empty());
FilterNode filterNode = new FilterNode(context.getIdAllocator().getNextId(), rowNumberNode, castToRowExpression(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, toSymbolReference(rowNumberSymbol), new GenericLiteral("BIGINT", Long.toString(parent.getCount())))));
ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), filterNode, AssignmentUtils.identityAsSymbolReferences(parent.getOutputSymbols()));
return Result.ofPlanNode(projectNode);
}
Aggregations