Search in sources :

Example 16 with FilterNode

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;
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) FilterNode(io.prestosql.spi.plan.FilterNode) PlanFragment(io.prestosql.sql.planner.PlanFragment) LinkedList(java.util.LinkedList)

Example 17 with FilterNode

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()));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) ImmutableList(com.google.common.collect.ImmutableList) FilterNode(io.prestosql.spi.plan.FilterNode) Assignments(io.prestosql.spi.plan.Assignments) AggregationNode(io.prestosql.spi.plan.AggregationNode) ImmutableMap(com.google.common.collect.ImmutableMap) Aggregation(io.prestosql.spi.plan.AggregationNode.Aggregation) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) ProjectNode(io.prestosql.spi.plan.ProjectNode) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 18 with FilterNode

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())));
}
Also used : FilterNode(io.prestosql.spi.plan.FilterNode) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Example 19 with FilterNode

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);
}
Also used : WindowNode(io.prestosql.spi.plan.WindowNode) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Example 20 with FilterNode

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);
}
Also used : ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Symbol(io.prestosql.spi.plan.Symbol) FilterNode(io.prestosql.spi.plan.FilterNode) RowNumberNode(io.prestosql.sql.planner.plan.RowNumberNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Aggregations

FilterNode (io.prestosql.spi.plan.FilterNode)49 PlanNode (io.prestosql.spi.plan.PlanNode)33 Symbol (io.prestosql.spi.plan.Symbol)32 TableScanNode (io.prestosql.spi.plan.TableScanNode)27 RowExpression (io.prestosql.spi.relation.RowExpression)25 Expression (io.prestosql.sql.tree.Expression)24 ProjectNode (io.prestosql.spi.plan.ProjectNode)23 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)19 Map (java.util.Map)18 Optional (java.util.Optional)18 ImmutableList (com.google.common.collect.ImmutableList)17 Session (io.prestosql.Session)17 List (java.util.List)17 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)16 JoinNode (io.prestosql.spi.plan.JoinNode)14 Metadata (io.prestosql.metadata.Metadata)13 Test (org.testng.annotations.Test)13 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)12 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)12 CallExpression (io.prestosql.spi.relation.CallExpression)11