Search in sources :

Example 16 with OrderingScheme

use of com.facebook.presto.spi.plan.OrderingScheme in project presto by prestodb.

the class PlannerUtils method toOrderingScheme.

public static OrderingScheme toOrderingScheme(List<VariableReferenceExpression> orderingSymbols, List<SortOrder> sortOrders) {
    ImmutableList.Builder<Ordering> builder = ImmutableList.builder();
    // don't override existing keys, i.e. when "ORDER BY a ASC, a DESC" is specified
    Set<VariableReferenceExpression> keysSeen = new HashSet<>();
    forEachPair(orderingSymbols.stream(), sortOrders.stream(), (variable, sortOrder) -> {
        if (!keysSeen.contains(variable)) {
            keysSeen.add(variable);
            builder.add(new Ordering(variable, sortOrder));
        }
    });
    return new OrderingScheme(builder.build());
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Ordering(com.facebook.presto.spi.plan.Ordering) HashSet(java.util.HashSet)

Example 17 with OrderingScheme

use of com.facebook.presto.spi.plan.OrderingScheme in project presto by prestodb.

the class TestPruneUnreferencedOutputs method windowNodePruning.

/**
 * Test that the unreferenced output pruning works correctly when WindowNode is pruned as no downstream operators are consuming the window function output
 */
@Test
public void windowNodePruning() {
    FunctionHandle functionHandle = createTestMetadataManager().getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
    CallExpression call = call("rank", functionHandle, BIGINT);
    WindowNode.Frame frame = new WindowNode.Frame(RANGE, UNBOUNDED_PRECEDING, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
    assertRuleApplication().on(p -> p.output(ImmutableList.of("user_uuid"), ImmutableList.of(p.variable("user_uuid", VARCHAR)), p.project(Assignments.of(p.variable("user_uuid", VARCHAR), p.variable("user_uuid", VARCHAR)), p.window(new WindowNode.Specification(ImmutableList.of(p.variable("user_uuid", VARCHAR)), Optional.of(new OrderingScheme(ImmutableList.of(new Ordering(p.variable("expr"), SortOrder.ASC_NULLS_LAST), new Ordering(p.variable("random"), SortOrder.ASC_NULLS_LAST))))), ImmutableMap.of(p.variable("rank"), new WindowNode.Function(call, frame, false)), p.project(Assignments.builder().put(p.variable("user_uuid", VARCHAR), p.variable("user_uuid", VARCHAR)).put(p.variable("expr", BIGINT), p.variable("expr", BIGINT)).put(p.variable("random", BIGINT), p.rowExpression("random()")).build(), p.values(p.variable("user_uuid", VARCHAR), p.variable("expr", BIGINT))))))).matches(output(project(project(values("user_uuid")))));
}
Also used : BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) SortOrder(com.facebook.presto.common.block.SortOrder) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) ImmutableMap(com.google.common.collect.ImmutableMap) Ordering(com.facebook.presto.spi.plan.Ordering) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) Assignments(com.facebook.presto.spi.plan.Assignments) Test(org.testng.annotations.Test) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) OptimizerAssert(com.facebook.presto.sql.planner.assertions.OptimizerAssert) RANGE(com.facebook.presto.sql.planner.plan.WindowNode.Frame.WindowType.RANGE) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) CallExpression(com.facebook.presto.spi.relation.CallExpression) UNBOUNDED_PRECEDING(com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_PRECEDING) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) UNBOUNDED_FOLLOWING(com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_FOLLOWING) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) Ordering(com.facebook.presto.spi.plan.Ordering) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 18 with OrderingScheme

use of com.facebook.presto.spi.plan.OrderingScheme in project presto by prestodb.

the class TestPinotQueryGenerator method testAggregationWithOrderByPushDownInTopN.

@Test(expectedExceptions = NoSuchElementException.class)
public void testAggregationWithOrderByPushDownInTopN() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
    AggregationNode agg = planBuilder.aggregation(aggBuilder -> aggBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("agg"), getRowExpression("sum(fare)", defaultSessionHolder)));
    TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), agg, 50L, new OrderingScheme(ImmutableList.of(new Ordering(variable("city"), SortOrder.DESC_NULLS_FIRST))), TopNNode.Step.FINAL);
    testPinotQuery(pinotConfig, topN, "", defaultSessionHolder, ImmutableMap.of());
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) Ordering(com.facebook.presto.spi.plan.Ordering) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TopNNode(com.facebook.presto.spi.plan.TopNNode) Test(org.testng.annotations.Test)

Aggregations

OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)18 Ordering (com.facebook.presto.spi.plan.Ordering)15 Test (org.testng.annotations.Test)10 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)9 SortOrder (com.facebook.presto.common.block.SortOrder)7 ImmutableList (com.google.common.collect.ImmutableList)6 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)5 PlanNode (com.facebook.presto.spi.plan.PlanNode)5 TopNNode (com.facebook.presto.spi.plan.TopNNode)5 RowExpression (com.facebook.presto.spi.relation.RowExpression)5 WindowNode (com.facebook.presto.sql.planner.plan.WindowNode)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 CallExpression (com.facebook.presto.spi.relation.CallExpression)4 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)3 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 PrestoWarning (com.facebook.presto.spi.PrestoWarning)2 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)2 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)2 PlannerUtils.toOrderingScheme (com.facebook.presto.sql.planner.PlannerUtils.toOrderingScheme)2