Search in sources :

Example 1 with EnforceSingleRowNode

use of io.prestosql.sql.planner.plan.EnforceSingleRowNode in project hetu-core by openlookeng.

the class SubqueryPlanner method appendScalarSubqueryApplyNode.

private PlanBuilder appendScalarSubqueryApplyNode(PlanBuilder subPlan, SubqueryExpression scalarSubquery, boolean correlationAllowed) {
    if (subPlan.canTranslate(scalarSubquery)) {
        // given subquery is already appended
        return subPlan;
    }
    List<Expression> coercions = coercionsFor(scalarSubquery);
    SubqueryExpression uncoercedScalarSubquery = uncoercedSubquery(scalarSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedScalarSubquery);
    subqueryPlan = subqueryPlan.withNewRoot(new EnforceSingleRowNode(idAllocator.getNextId(), subqueryPlan.getRoot()));
    subqueryPlan = subqueryPlan.appendProjections(coercions, planSymbolAllocator, idAllocator);
    Symbol uncoercedScalarSubquerySymbol = subqueryPlan.translate(uncoercedScalarSubquery);
    subPlan.getTranslations().put(uncoercedScalarSubquery, uncoercedScalarSubquerySymbol);
    for (Expression coercion : coercions) {
        Symbol coercionSymbol = subqueryPlan.translate(coercion);
        subPlan.getTranslations().put(coercion, coercionSymbol);
    }
    // The subquery's EnforceSingleRowNode always produces a row, so the join is effectively INNER
    return appendLateralJoin(subPlan, subqueryPlan, scalarSubquery.getQuery(), correlationAllowed, LateralJoinNode.Type.INNER, TRUE_LITERAL);
}
Also used : OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) ExpressionNodeInliner.replaceExpression(io.prestosql.sql.planner.ExpressionNodeInliner.replaceExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) NotExpression(io.prestosql.sql.tree.NotExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) EnforceSingleRowNode(io.prestosql.sql.planner.plan.EnforceSingleRowNode) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression)

Example 2 with EnforceSingleRowNode

use of io.prestosql.sql.planner.plan.EnforceSingleRowNode in project hetu-core by openlookeng.

the class TestCostCalculator method testEnforceSingleRow.

@Test
public void testEnforceSingleRow() {
    TableScanNode ts1 = tableScan("ts1", "orderkey");
    EnforceSingleRowNode singleRow = new EnforceSingleRowNode(new PlanNodeId("singleRow"), ts1);
    Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of("ts1", statsEstimate(ts1, 4000), "singleRow", // 1 * Average Row Size
    statsEstimate(ts1, 8));
    Map<String, PlanCostEstimate> costs = ImmutableMap.of("ts1", cpuCost(1000));
    Map<String, Type> types = ImmutableMap.of("orderkey", BIGINT);
    assertCost(singleRow, costs, stats, types).cpu(// Only count the accumulated cost of source nodes
    1000).memory(0).network(0);
    assertCostEstimatedExchanges(singleRow, costs, stats, types).cpu(1000).memory(0).network(0);
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) TableScanNode(io.prestosql.spi.plan.TableScanNode) EnforceSingleRowNode(io.prestosql.sql.planner.plan.EnforceSingleRowNode) Test(org.testng.annotations.Test)

Aggregations

EnforceSingleRowNode (io.prestosql.sql.planner.plan.EnforceSingleRowNode)2 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)1 Symbol (io.prestosql.spi.plan.Symbol)1 TableScanNode (io.prestosql.spi.plan.TableScanNode)1 RowExpression (io.prestosql.spi.relation.RowExpression)1 Type (io.prestosql.spi.type.Type)1 ExpressionNodeInliner.replaceExpression (io.prestosql.sql.planner.ExpressionNodeInliner.replaceExpression)1 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)1 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)1 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)1 Expression (io.prestosql.sql.tree.Expression)1 NotExpression (io.prestosql.sql.tree.NotExpression)1 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)1 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)1 Test (org.testng.annotations.Test)1