void tst_TimelineModelAggregator::addRemoveModel() { Timeline::TimelineNotesModel notes; Timeline::TimelineModelAggregator aggregator(¬es); QSignalSpy spy(&aggregator, SIGNAL(modelsChanged())); QCOMPARE(aggregator.notes(), ¬es); Timeline::TimelineModel *model1 = new Timeline::TimelineModel(&aggregator); Timeline::TimelineModel *model2 = new Timeline::TimelineModel(&aggregator); aggregator.addModel(model1); QCOMPARE(spy.count(), 1); QCOMPARE(aggregator.modelCount(), 1); QCOMPARE(aggregator.model(0), model1); QCOMPARE(aggregator.models().count(), 1); aggregator.addModel(model2); QCOMPARE(spy.count(), 2); QCOMPARE(aggregator.modelCount(), 2); QCOMPARE(aggregator.model(1), model2); QCOMPARE(aggregator.models().count(), 2); QCOMPARE(aggregator.modelIndexById(model1->modelId()), 0); QCOMPARE(aggregator.modelIndexById(model2->modelId()), 1); QCOMPARE(aggregator.modelIndexById(aggregator.generateModelId()), -1); QCOMPARE(aggregator.modelOffset(0), 0); QCOMPARE(aggregator.modelOffset(1), 0); aggregator.clear(); QCOMPARE(spy.count(), 3); QCOMPARE(aggregator.modelCount(), 0); }
bool InitStylist(FeatureType & f, int8_t deviceLang, int const zoomLevel, bool buildings3d, Stylist & s) { feature::TypesHolder const types(f); if (!buildings3d && IsBuildingPartChecker::Instance()(types) && !ftypes::IsBuildingChecker::Instance()(types)) return false; drule::KeysT keys; auto const geomType = feature::GetDrawRule(types, zoomLevel, keys); feature::FilterRulesByRuntimeSelector(f, zoomLevel, keys); if (keys.empty()) return false; drule::MakeUnique(keys); if (geomType.second) s.RaiseCoastlineFlag(); auto const mainGeomType = feature::EGeomType(geomType.first); switch (mainGeomType) { case feature::GEOM_POINT: s.RaisePointStyleFlag(); break; case feature::GEOM_LINE : s.RaiseLineStyleFlag(); break; case feature::GEOM_AREA : s.RaiseAreaStyleFlag(); break; default: ASSERT(false, ()); return false; } Aggregator aggregator(f, mainGeomType, zoomLevel, static_cast<int>(keys.size())); aggregator.AggregateKeys(keys); CaptionDescription & descr = s.GetCaptionDescriptionImpl(); descr.Init(f, deviceLang, zoomLevel, mainGeomType, aggregator.m_mainTextType, aggregator.m_auxCaptionFound); aggregator.AggregateStyleFlags(keys, descr.IsNameExists()); if (aggregator.m_pointStyleFound) s.RaisePointStyleFlag(); if (aggregator.m_lineStyleFound) s.RaiseLineStyleFlag(); s.m_rules.swap(aggregator.m_rules); return true; }
void run_example() { std::cout << "Running cache read " << ITERATIONS_NUMBER << " times" << std::endl; react::stream_aggregator_t aggregator(std::cout); for (int i = 0; i < ITERATIONS_NUMBER; ++i) { react_activate(&aggregator); std::string data = cache_read(); react_deactivate(); } }
double GetFeaturePriority(FeatureType & f, int const zoomLevel) { drule::KeysT keys; std::pair<int, bool> const geomType = feature::GetDrawRule(feature::TypesHolder(f), zoomLevel, keys); feature::FilterRulesByRuntimeSelector(f, zoomLevel, keys); auto const mainGeomType = feature::EGeomType(geomType.first); Aggregator aggregator(f, mainGeomType, zoomLevel, static_cast<int>(keys.size())); aggregator.AggregateKeys(keys); double maxPriority = kMinPriority; for (auto const & rule : aggregator.m_rules) { if (rule.second > maxPriority) maxPriority = rule.second; } return maxPriority; }
/** * @brief Creates logical tile(s) wrapping the results of aggregation. * @return true on success, false otherwise. */ bool AggregateExecutor::DExecute() { // Already performed the aggregation if (done) { if (result_itr == INVALID_OID || result_itr == result.size()) { return false; } else { // Return appropriate tile and go to next tile SetOutput(result[result_itr]); result_itr++; return true; } } // Grab info from plan node const planner::AggregatePlan &node = GetPlanNode<planner::AggregatePlan>(); // Get an aggregator std::unique_ptr<AbstractAggregator> aggregator(nullptr); // Get input tiles and aggregate them while (children_[0]->Execute() == true) { std::unique_ptr<LogicalTile> tile(children_[0]->GetOutput()); if (nullptr == aggregator.get()) { // Initialize the aggregator switch (node.GetAggregateStrategy()) { case AGGREGATE_TYPE_HASH: LOG_TRACE("Use HashAggregator"); aggregator.reset(new HashAggregator( &node, output_table, executor_context_, tile->GetColumnCount())); break; case AGGREGATE_TYPE_SORTED: LOG_TRACE("Use SortedAggregator"); aggregator.reset(new SortedAggregator( &node, output_table, executor_context_, tile->GetColumnCount())); break; case AGGREGATE_TYPE_PLAIN: LOG_TRACE("Use PlainAggregator"); aggregator.reset( new PlainAggregator(&node, output_table, executor_context_)); break; default: LOG_ERROR("Invalid aggregate type. Return."); return false; } } LOG_TRACE("Looping over tile.."); for (oid_t tuple_id : *tile) { std::unique_ptr<expression::ContainerTuple<LogicalTile>> cur_tuple( new expression::ContainerTuple<LogicalTile>(tile.get(), tuple_id)); if (aggregator->Advance(cur_tuple.get()) == false) { return false; } } LOG_TRACE("Finished processing logical tile"); } LOG_TRACE("Finalizing.."); if (!aggregator.get() || !aggregator->Finalize()) { // If there's no tuples and no group-by, count() aggregations should return // 0 according to the test in MySQL. // TODO: We only checked whether all AggTerms are counts here. If there're // mixed terms, we should return 0 for counts and null for others. bool all_count_aggs = true; for (oid_t aggno = 0; aggno < node.GetUniqueAggTerms().size(); aggno++) { auto agg_type = node.GetUniqueAggTerms()[aggno].aggtype; if (agg_type != EXPRESSION_TYPE_AGGREGATE_COUNT && agg_type != EXPRESSION_TYPE_AGGREGATE_COUNT_STAR) all_count_aggs = false; } // If there's no tuples in the table and only if no group-by in the // query, // we should return a NULL tuple // this is required by SQL if (!aggregator.get() && node.GetGroupbyColIds().empty()) { LOG_TRACE( "No tuples received and no group-by. Should insert a NULL tuple " "here."); std::unique_ptr<storage::Tuple> tuple( new storage::Tuple(output_table->GetSchema(), true)); if (all_count_aggs == true) { tuple->SetAllZeros(); } else { tuple->SetAllNulls(); } auto location = output_table->InsertTuple(tuple.get()); PL_ASSERT(location.block != INVALID_OID); auto &manager = catalog::Manager::GetInstance(); auto tile_group_header = manager.GetTileGroup(location.block)->GetHeader(); tile_group_header->SetTransactionId(location.offset, INITIAL_TXN_ID); } else { done = true; return false; } } // Transform output table into result auto tile_group_count = output_table->GetTileGroupCount(); if (tile_group_count == 0) return false; for (oid_t tile_group_itr = 0; tile_group_itr < tile_group_count; tile_group_itr++) { auto tile_group = output_table->GetTileGroup(tile_group_itr); // Get the logical tiles corresponding to the given tile group auto logical_tile = LogicalTileFactory::WrapTileGroup(tile_group); result.push_back(logical_tile); } done = true; LOG_TRACE("Result tiles : %lu ", result.size()); SetOutput(result[result_itr]); result_itr++; return true; }
/** * @brief Creates logical tile(s) wrapping the results of aggregation. * @return true on success, false otherwise. */ bool AggregateExecutor::DExecute() { // Already performed the aggregation if (done) { if (result_itr == INVALID_OID || result_itr == result.size()) { return false; } else { // Return appropriate tile and go to next tile SetOutput(result[result_itr]); result_itr++; return true; } } // Grab info from plan node const planner::AggregatePlan &node = GetPlanNode<planner::AggregatePlan>(); // Get an aggregator std::unique_ptr<AbstractAggregator> aggregator(nullptr); // Get input tiles and aggregate them while (children_[0]->Execute() == true) { std::unique_ptr<LogicalTile> tile(children_[0]->GetOutput()); if (nullptr == aggregator.get()) { // Initialize the aggregator switch (node.GetAggregateStrategy()) { case AGGREGATE_TYPE_HASH: LOG_INFO("Use HashAggregator\n"); aggregator.reset(new HashAggregator( &node, output_table, executor_context_, tile->GetColumnCount())); break; case AGGREGATE_TYPE_SORTED: LOG_INFO("Use SortedAggregator\n"); aggregator.reset(new SortedAggregator( &node, output_table, executor_context_, tile->GetColumnCount())); break; case AGGREGATE_TYPE_PLAIN: LOG_INFO("Use PlainAggregator\n"); aggregator.reset( new PlainAggregator(&node, output_table, executor_context_)); break; default: LOG_ERROR("Invalid aggregate type. Return.\n"); return false; } } LOG_INFO("Looping over tile.."); for (oid_t tuple_id : *tile) { std::unique_ptr<expression::ContainerTuple<LogicalTile>> cur_tuple( new expression::ContainerTuple<LogicalTile>(tile.get(), tuple_id)); if (aggregator->Advance(cur_tuple.get()) == false) { return false; } } LOG_TRACE("Finished processing logical tile"); } LOG_INFO("Finalizing.."); if (!aggregator.get() || !aggregator->Finalize()) { // If there's no tuples in the table and only if no group-by in the query, // we should return a NULL tuple // this is required by SQL if (!aggregator.get() && node.GetGroupbyColIds().empty()) { LOG_INFO( "No tuples received and no group-by. Should insert a NULL tuple " "here."); std::unique_ptr<storage::Tuple> tuple( new storage::Tuple(output_table->GetSchema(), true)); tuple->SetAllNulls(); output_table->InsertTuple(executor_context_->GetTransaction(), tuple.get()); } else { done = true; return false; } } // Transform output table into result auto tile_group_count = output_table->GetTileGroupCount(); if (tile_group_count == 0) return false; for (oid_t tile_group_itr = 0; tile_group_itr < tile_group_count; tile_group_itr++) { auto tile_group = output_table->GetTileGroup(tile_group_itr); // Get the logical tiles corresponding to the given tile group auto logical_tile = LogicalTileFactory::WrapTileGroup(tile_group); result.push_back(logical_tile); } done = true; LOG_INFO("Result tiles : %lu \n", result.size()); SetOutput(result[result_itr]); result_itr++; return true; }