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);
}
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());
}
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());
}
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);
}
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()));
}
Aggregations