Search in sources :

Example 1 with OrderingScheme

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

the class TestPinotQueryGeneratorSql method testDefaultNoTopNPushdown.

@Test
public void testDefaultNoTopNPushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
    AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)));
    pinotConfig.setPushdownTopNBrokerQueries(false);
    TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    Optional<PinotQueryGenerator.PinotQueryGeneratorResult> generatedQuery = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(topN, defaultSessionHolder.getConnectorSession());
    assertFalse(generatedQuery.isPresent());
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    testPinotQuery(pinotConfig, aggregationNode, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city LIMIT 10000", sessionHolder, 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)

Example 2 with OrderingScheme

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

the class TestPinotQueryGeneratorSql method testAggregationWithOrderByPushDownInTopN.

@Override
@Test
public void testAggregationWithOrderByPushDownInTopN() {
    pinotConfig.setPushdownTopNBrokerQueries(true);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
    AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)));
    testPinotQuery(pinotConfig, aggregationNode, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city LIMIT 10000", sessionHolder, ImmutableMap.of());
    TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 50L, new OrderingScheme(ImmutableList.of(new Ordering(variable("city"), SortOrder.DESC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000L, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY sum(fare) LIMIT 1000", sessionHolder, ImmutableMap.of());
    topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000L, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
    testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY sum(fare) LIMIT 1000", sessionHolder, 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)

Example 3 with OrderingScheme

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

the class TestVerifyNoOriginalExpression method testValidateForWindow.

@Test
public void testValidateForWindow() {
    Optional<VariableReferenceExpression> startValue = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
    Optional<VariableReferenceExpression> endValue = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
    Optional<String> originalStartValue = Optional.of("count");
    Optional<String> originalEndValue = Optional.of("count");
    WindowNode.Frame frame = new WindowNode.Frame(WindowNode.Frame.WindowType.RANGE, WindowNode.Frame.BoundType.UNBOUNDED_FOLLOWING, startValue, WindowNode.Frame.BoundType.UNBOUNDED_FOLLOWING, endValue, originalStartValue, originalEndValue);
    WindowNode.Function function = new WindowNode.Function(comparisonCallExpression, frame, false);
    ImmutableList<VariableReferenceExpression> partitionBy = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
    Optional<OrderingScheme> orderingScheme = Optional.empty();
    ImmutableMap<VariableReferenceExpression, WindowNode.Function> functions = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, function);
    WindowNode windowNode = builder.window(new WindowNode.Specification(partitionBy, orderingScheme), functions, valuesNode);
    testValidation(windowNode);
}
Also used : WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 4 with OrderingScheme

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

the class TestVerifyNoOriginalExpression method testAggregation.

@Test
public void testAggregation() {
    ImmutableList<VariableReferenceExpression> groupingKeys = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
    int groupingSetCount = 1;
    ImmutableMap<VariableReferenceExpression, SortOrder> orderings = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, SortOrder.ASC_NULLS_FIRST);
    OrderingScheme orderingScheme = new OrderingScheme(groupingKeys.stream().map(variable -> new Ordering(variable, orderings.get(variable))).collect(toImmutableList()));
    ImmutableMap<VariableReferenceExpression, AggregationNode.Aggregation> aggregations = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, new AggregationNode.Aggregation(comparisonCallExpression, Optional.of(comparisonCallExpression), Optional.of(orderingScheme), false, Optional.of(new VariableReferenceExpression(Optional.empty(), "orderkey", BIGINT))));
    ImmutableSet<Integer> globalGroupingSets = ImmutableSet.of(1);
    AggregationNode.GroupingSetDescriptor groupingSets = new AggregationNode.GroupingSetDescriptor(groupingKeys, groupingSetCount, globalGroupingSets);
    ImmutableList<VariableReferenceExpression> preGroupedVariables = ImmutableList.of();
    Optional<VariableReferenceExpression> hashVariable = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
    Optional<VariableReferenceExpression> groupIdVariable = Optional.of(VARIABLE_REFERENCE_EXPRESSION);
    AggregationNode aggregationNode = new AggregationNode(Optional.empty(), new PlanNodeId("1"), valuesNode, aggregations, groupingSets, preGroupedVariables, AggregationNode.Step.SINGLE, hashVariable, groupIdVariable);
    testValidation(aggregationNode);
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) SortOrder(com.facebook.presto.common.block.SortOrder) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Ordering(com.facebook.presto.spi.plan.Ordering) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 5 with OrderingScheme

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

the class PushAggregationThroughOuterJoin method inlineOrderByVariables.

private static OrderingScheme inlineOrderByVariables(Map<VariableReferenceExpression, VariableReferenceExpression> variableMapping, OrderingScheme orderingScheme) {
    // This is a logic expanded from ExpressionTreeRewriter::rewriteSortItems
    ImmutableList.Builder<VariableReferenceExpression> orderBy = ImmutableList.builder();
    ImmutableMap.Builder<VariableReferenceExpression, SortOrder> ordering = new ImmutableMap.Builder<>();
    for (VariableReferenceExpression variable : orderingScheme.getOrderByVariables()) {
        VariableReferenceExpression translated = variableMapping.get(variable);
        orderBy.add(translated);
        ordering.put(translated, orderingScheme.getOrdering(variable));
    }
    ImmutableMap<VariableReferenceExpression, SortOrder> orderingMap = ordering.build();
    return new OrderingScheme(orderBy.build().stream().map(variable -> new Ordering(variable, orderingMap.get(variable))).collect(toImmutableList()));
}
Also used : OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Ordering(com.facebook.presto.spi.plan.Ordering) SortOrder(com.facebook.presto.common.block.SortOrder) ImmutableMap(com.google.common.collect.ImmutableMap)

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