Search in sources :

Example 1 with UNBOUNDED_PRECEDING

use of com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_PRECEDING 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)

Aggregations

SortOrder (com.facebook.presto.common.block.SortOrder)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 VARCHAR (com.facebook.presto.common.type.VarcharType.VARCHAR)1 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)1 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)1 Assignments (com.facebook.presto.spi.plan.Assignments)1 Ordering (com.facebook.presto.spi.plan.Ordering)1 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)1 CallExpression (com.facebook.presto.spi.relation.CallExpression)1 OptimizerAssert (com.facebook.presto.sql.planner.assertions.OptimizerAssert)1 PlanMatchPattern.output (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output)1 PlanMatchPattern.project (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project)1 PlanMatchPattern.values (com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values)1 BaseRuleTest (com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)1 RuleTester (com.facebook.presto.sql.planner.iterative.rule.test.RuleTester)1 WindowNode (com.facebook.presto.sql.planner.plan.WindowNode)1 UNBOUNDED_FOLLOWING (com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_FOLLOWING)1 UNBOUNDED_PRECEDING (com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_PRECEDING)1 RANGE (com.facebook.presto.sql.planner.plan.WindowNode.Frame.WindowType.RANGE)1 Expressions.call (com.facebook.presto.sql.relational.Expressions.call)1