public PlanNodeId getNextId() { return new PlanNodeId(Integer.toString(nextId++)); } }
private PlanNode reportDuplicateId(PlanNode first, PlanNode second) { requireNonNull(first, "first is null"); requireNonNull(second, "second is null"); checkArgument(first.getId().equals(second.getId())); throw new IllegalStateException(format( "Generated plan contains nodes with duplicated id %s: %s and %s", first.getId(), first, second)); } }
private static int compare(WindowNode o1, WindowNode o2) { int comparison = comparePartitionBy(o1, o2); if (comparison != 0) { return comparison; } comparison = compareOrderBy(o1, o2); if (comparison != 0) { return comparison; } // If PartitionBy and OrderBy clauses are identical, let's establish an arbitrary order to prevent non-deterministic results of swapping WindowNodes in such a case return o1.getId().toString().compareTo(o2.getId().toString()); }
@Override protected List<? extends OperatorFactory> createOperatorFactories() { OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice"); return ImmutableList.of(tableScanOperator); }
public void updateSource(TaskSource sourceUpdate) { checkLockNotHeld("Can not update sources while holding the driver lock"); checkArgument( sourceOperator.isPresent() && sourceOperator.get().getSourceId().equals(sourceUpdate.getPlanNodeId()), "sourceUpdate is for a plan node that is different from this Driver's source node"); // stage the new updates pendingTaskSourceUpdates.updateAndGet(current -> current == null ? sourceUpdate : current.update(sourceUpdate)); // attempt to get the lock and process the updates we staged above // updates will be processed in close if and only if we got the lock tryWithLock(() -> TRUE); }
private StatsCalculator statsCalculator(Map<String, PlanNodeStatsEstimate> stats) { return (node, sourceStats, lookup, session, types) -> requireNonNull(stats.get(node.getId().toString()), "no stats for node"); }
@Override protected List<? extends OperatorFactory> createOperatorFactories() { List<Type> tableScanTypes = getColumnTypes("orders", "totalprice"); OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice"); TopNOperatorFactory topNOperator = new TopNOperatorFactory( 1, new PlanNodeId("test"), tableScanTypes, 100, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST)); return ImmutableList.of(tableScanOperator, topNOperator); }
public TaskSource update(TaskSource source) { checkArgument(planNodeId.equals(source.getPlanNodeId()), "Expected source %s, but got source %s", planNodeId, source.getPlanNodeId()); if (isNewer(source)) { // assure the new source is properly formed // we know that either the new source one has new splits and/or it is marking the source as closed checkArgument(!noMoreSplits || splits.containsAll(source.getSplits()), "Source %s has new splits, but no more splits already set", planNodeId); Set<ScheduledSplit> newSplits = ImmutableSet.<ScheduledSplit>builder() .addAll(splits) .addAll(source.getSplits()) .build(); Set<Lifespan> newNoMoreSplitsForDriverGroup = ImmutableSet.<Lifespan>builder() .addAll(noMoreSplitsForLifespan) .addAll(source.getNoMoreSplitsForLifespan()) .build(); return new TaskSource( planNodeId, newSplits, newNoMoreSplitsForDriverGroup, source.isNoMoreSplits()); } else { // the specified source is older than this one return this; } }
protected DriverFactory createDriverFactory() { List<OperatorFactory> operatorFactories = new ArrayList<>(createOperatorFactories()); operatorFactories.add(new NullOutputOperatorFactory(999, new PlanNodeId("test"))); return new DriverFactory(0, true, true, operatorFactories, OptionalInt.empty(), UNGROUPED_EXECUTION); }
public StatsCalculatorAssertion withSourceStats(PlanNodeId planNodeId, PlanNodeStatsEstimate sourceStats) { PlanNode sourceNode = PlanNodeSearcher.searchFrom(planNode).where(node -> node.getId().equals(planNodeId)).findOnlyElement(); sourcesStats.put(sourceNode, sourceStats); return this; }
private CostAssertionBuilder assertCost( CostCalculator costCalculator, PlanNode node, Map<String, PlanNodeCostEstimate> costs, Map<String, PlanNodeStatsEstimate> stats, Map<String, Type> types) { PlanNodeCostEstimate cumulativeCost = calculateCumulativeCost( costCalculator, node, planNode -> costs.get(planNode.getId().toString()), planNode -> stats.get(planNode.getId().toString()), types); return new CostAssertionBuilder(cumulativeCost); }
@Override protected List<? extends OperatorFactory> createOperatorFactories() { List<Type> tableScanTypes = getColumnTypes("orders", "totalprice", "clerk"); OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice", "clerk"); LimitOperatorFactory limitOperator = new LimitOperatorFactory(1, new PlanNodeId("test"), ROWS); OrderByOperatorFactory orderByOperator = new OrderByOperatorFactory( 2, new PlanNodeId("test"), tableScanTypes, ImmutableList.of(1), ROWS, ImmutableList.of(0), ImmutableList.of(ASC_NULLS_LAST), new PagesIndex.TestingFactory(false)); return ImmutableList.of(tableScanOperator, limitOperator, orderByOperator); }
@Override public PlanNodeStats mergeWith(PlanNodeStats other) { checkArgument(planNodeId.equals(other.getPlanNodeId()), "planNodeIds do not match. %s != %s", planNodeId, other.getPlanNodeId()); long planNodeInputPositions = this.planNodeInputPositions + other.planNodeInputPositions; DataSize planNodeInputDataSize = succinctBytes(this.planNodeInputDataSize.toBytes() + other.planNodeInputDataSize.toBytes()); long planNodeOutputPositions = this.planNodeOutputPositions + other.planNodeOutputPositions; DataSize planNodeOutputDataSize = succinctBytes(this.planNodeOutputDataSize.toBytes() + other.planNodeOutputDataSize.toBytes()); Map<String, OperatorInputStats> operatorInputStats = mergeMaps(this.operatorInputStats, other.operatorInputStats, OperatorInputStats::merge); Map<String, OperatorHashCollisionsStats> operatorHashCollisionsStats = mergeMaps(this.operatorHashCollisionsStats, other.operatorHashCollisionsStats, OperatorHashCollisionsStats::merge); Optional<WindowOperatorStats> windowNodeStats = Mergeable.merge(this.windowOperatorStats, other.windowOperatorStats); return new PlanNodeStats( planNodeId, new Duration(planNodeScheduledTime.toMillis() + other.getPlanNodeScheduledTime().toMillis(), MILLISECONDS), new Duration(planNodeCpuTime.toMillis() + other.getPlanNodeCpuTime().toMillis(), MILLISECONDS), planNodeInputPositions, planNodeInputDataSize, planNodeOutputPositions, planNodeOutputDataSize, operatorInputStats, operatorHashCollisionsStats, windowNodeStats); } }
@Override public Operator createOperator(DriverContext driverContext) { OperatorContext operatorContext = driverContext.addOperatorContext(operatorId, new PlanNodeId("test"), TpchQuery1Operator.class.getSimpleName()); return new TpchQuery1Operator(operatorContext); }
private static PlanNodeId newId() { return new PlanNodeId(UUID.randomUUID().toString()); } }
private static PlanNodeId newId() { return new PlanNodeId(UUID.randomUUID().toString()); } }
private static PlanNodeId newId() { return new PlanNodeId(UUID.randomUUID().toString()); }
@Override protected List<? extends OperatorFactory> createOperatorFactories() { OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey"); InternalAggregationFunction countFunction = localQueryRunner.getMetadata().getFunctionRegistry().getAggregateFunctionImplementation( new Signature("count", AGGREGATE, BIGINT.getTypeSignature())); AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(countFunction.bind(ImmutableList.of(0), Optional.empty())), false); return ImmutableList.of(tableScanOperator, aggregationOperator); }
@Override protected List<? extends OperatorFactory> createOperatorFactories() { OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice"); InternalAggregationFunction doubleSum = MetadataManager.createTestMetadataManager().getFunctionRegistry().getAggregateFunctionImplementation( new Signature("sum", AGGREGATE, DOUBLE.getTypeSignature(), DOUBLE.getTypeSignature())); AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(doubleSum.bind(ImmutableList.of(0), Optional.empty())), false); return ImmutableList.of(tableScanOperator, aggregationOperator); }