Search in sources :

Example 16 with TypeProvider

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

the class DetermineSemiJoinDistributionType method getSemiJoinNodeWithCost.

private PlanNodeWithCost getSemiJoinNodeWithCost(SemiJoinNode possibleJoinNode, Context context) {
    TypeProvider types = context.getSymbolAllocator().getTypes();
    StatsProvider stats = context.getStatsProvider();
    boolean replicated = possibleJoinNode.getDistributionType().get().equals(REPLICATED);
    /*
         *   HACK!
         *
         *   Currently cost model always has to compute the total cost of an operation.
         *   For SEMI-JOIN the total cost consist of 4 parts:
         *     - Cost of exchanges that have to be introduced to execute a JOIN
         *     - Cost of building a hash table
         *     - Cost of probing a hash table
         *     - Cost of building an output for matched rows
         *
         *   When output size for a SEMI-JOIN cannot be estimated the cost model returns
         *   UNKNOWN cost for the join.
         *
         *   However assuming the cost of SEMI-JOIN output is always the same, we can still make
         *   cost based decisions based on the input cost for different types of SEMI-JOINs.
         *
         *   TODO Decision about the distribution should be based on LocalCostEstimate only when PlanCostEstimate cannot be calculated. Otherwise cost comparator cannot take query.max-memory into account.
         */
    int estimatedSourceDistributedTaskCount = taskCountEstimator.estimateSourceDistributedTaskCount();
    LocalCostEstimate cost = calculateJoinCostWithoutOutput(possibleJoinNode.getSource(), possibleJoinNode.getFilteringSource(), stats, types, replicated, estimatedSourceDistributedTaskCount);
    return new PlanNodeWithCost(cost.toPlanCost(), possibleJoinNode);
}
Also used : StatsProvider(io.prestosql.cost.StatsProvider) TypeProvider(io.prestosql.sql.planner.TypeProvider) LocalCostEstimate(io.prestosql.cost.LocalCostEstimate)

Example 17 with TypeProvider

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

the class ExtractSpatialJoins method addProjection.

private static PlanNode addProjection(Context context, PlanNode node, Symbol symbol, RowExpression expression) {
    Assignments.Builder projections = Assignments.builder();
    TypeProvider typeProvider = context.getSymbolAllocator().getTypes();
    for (Symbol outputSymbol : node.getOutputSymbols()) {
        projections.put(outputSymbol, new VariableReferenceExpression(outputSymbol.getName(), typeProvider.get(outputSymbol)));
    }
    projections.put(symbol, expression);
    return new ProjectNode(context.getIdAllocator().getNextId(), node, projections.build());
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Assignments(io.prestosql.spi.plan.Assignments) TypeProvider(io.prestosql.sql.planner.TypeProvider) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Example 18 with TypeProvider

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

the class ExtractSpatialJoins method addPartitioningNodes.

private static PlanNode addPartitioningNodes(Metadata metadata, Context context, PlanNode node, Symbol partitionSymbol, KdbTree kdbTree, RowExpression geometry, Optional<RowExpression> radius) {
    Assignments.Builder projections = Assignments.builder();
    TypeProvider typeProvider = context.getSymbolAllocator().getTypes();
    for (Symbol outputSymbol : node.getOutputSymbols()) {
        projections.put(outputSymbol, new VariableReferenceExpression(outputSymbol.getName(), typeProvider.get(outputSymbol)));
    }
    ConstantExpression kdbConstant = Expressions.constant(utf8Slice(KdbTreeUtils.toJson(kdbTree)), VARCHAR);
    FunctionHandle castFunctionHandle = metadata.getFunctionAndTypeManager().lookupCast(CastType.CAST, VARCHAR.getTypeSignature(), parseTypeSignature(KDB_TREE_TYPENAME));
    ImmutableList.Builder partitioningArgumentsBuilder = ImmutableList.builder().add(new CallExpression(CastType.CAST.name(), castFunctionHandle, metadata.getType(parseTypeSignature(KDB_TREE_TYPENAME)), ImmutableList.of(kdbConstant), Optional.empty())).add(geometry);
    radius.map(partitioningArgumentsBuilder::add);
    List<RowExpression> partitioningArguments = partitioningArgumentsBuilder.build();
    String spatialPartitionsFunctionName = "spatial_partitions";
    FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction(spatialPartitionsFunctionName, fromTypes(partitioningArguments.stream().map(RowExpression::getType).collect(toImmutableList())));
    CallExpression partitioningFunction = new CallExpression(spatialPartitionsFunctionName, functionHandle, new ArrayType(INTEGER), partitioningArguments, Optional.empty());
    Symbol partitionsSymbol = context.getSymbolAllocator().newSymbol(partitioningFunction);
    projections.put(partitionsSymbol, partitioningFunction);
    return new UnnestNode(context.getIdAllocator().getNextId(), new ProjectNode(context.getIdAllocator().getNextId(), node, projections.build()), node.getOutputSymbols(), ImmutableMap.of(partitionsSymbol, ImmutableList.of(partitionSymbol)), Optional.empty());
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) Assignments(io.prestosql.spi.plan.Assignments) TypeProvider(io.prestosql.sql.planner.TypeProvider) RowExpression(io.prestosql.spi.relation.RowExpression) ArrayType(io.prestosql.spi.type.ArrayType) UnnestNode(io.prestosql.sql.planner.plan.UnnestNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ProjectNode(io.prestosql.spi.plan.ProjectNode) FunctionHandle(io.prestosql.spi.function.FunctionHandle) SpatialJoinUtils.getFlippedFunctionHandle(io.prestosql.util.SpatialJoinUtils.getFlippedFunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 19 with TypeProvider

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

the class TestCostCalculator method calculateCost.

private PlanCostEstimate calculateCost(PlanNode node, CostCalculator costCalculator, StatsCalculator statsCalculator, Map<String, Type> types) {
    TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream().collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)));
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator, session, typeProvider);
    CostProvider costProvider = new CachingCostProvider(costCalculator, statsProvider, Optional.empty(), session, typeProvider);
    return costProvider.getCost(node);
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) TypeProvider(io.prestosql.sql.planner.TypeProvider)

Example 20 with TypeProvider

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

the class TestCostCalculator method assertCostFragmentedPlan.

private CostAssertionBuilder assertCostFragmentedPlan(PlanNode node, Map<String, PlanCostEstimate> costs, Map<String, PlanNodeStatsEstimate> stats, Map<String, Type> types) {
    TypeProvider typeProvider = TypeProvider.copyOf(types.entrySet().stream().collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)));
    StatsProvider statsProvider = new CachingStatsProvider(statsCalculator(stats), session, typeProvider);
    CostProvider costProvider = new TestingCostProvider(costs, costCalculatorUsingExchanges, statsProvider, session, typeProvider);
    PlanNode plan = translateExpression(node, statsCalculator(stats), typeProvider);
    SubPlan subPlan = fragment(new Plan(plan, typeProvider, StatsAndCosts.create(plan, statsProvider, costProvider)));
    return new CostAssertionBuilder(subPlan.getFragment().getStatsAndCosts().getCosts().getOrDefault(plan.getId(), PlanCostEstimate.unknown()));
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) TypeProvider(io.prestosql.sql.planner.TypeProvider) SubPlan(io.prestosql.sql.planner.SubPlan) Plan(io.prestosql.sql.planner.Plan) SubPlan(io.prestosql.sql.planner.SubPlan)

Aggregations

TypeProvider (io.prestosql.sql.planner.TypeProvider)26 Symbol (io.prestosql.spi.plan.Symbol)19 Optional (java.util.Optional)12 Session (io.prestosql.Session)11 PlanNode (io.prestosql.spi.plan.PlanNode)9 RowExpression (io.prestosql.spi.relation.RowExpression)9 Expression (io.prestosql.sql.tree.Expression)9 Map (java.util.Map)9 Metadata (io.prestosql.metadata.Metadata)8 List (java.util.List)8 Objects.requireNonNull (java.util.Objects.requireNonNull)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)7 HashMap (java.util.HashMap)7 ImmutableList (com.google.common.collect.ImmutableList)6 Pattern (io.prestosql.matching.Pattern)6 FilterNode (io.prestosql.spi.plan.FilterNode)6 OriginalExpressionUtils.isExpression (io.prestosql.sql.relational.OriginalExpressionUtils.isExpression)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 ImmutableMap (com.google.common.collect.ImmutableMap)5