void GroupByScan::executeGroupBy() { auto resultTab = createResultTableLayout(); auto groupResults = getInputHashTable(); // Allocate some memory for the result tab and resize the table resultTab->resize(groupResults->numKeys()); pos_t row = 0; typename HashTableType::map_const_iterator_t it1, it2, end; // set iterators: in the sequential case, getInputTable() returns an AggregateHashTable, in the parallel case a HashTableView<> // Alternatively, a common type could be introduced if (_count < 1) { auto aggregateHashTable = std::dynamic_pointer_cast<const HashTableType>(groupResults); it1 = aggregateHashTable->getMapBegin(); end = aggregateHashTable->getMapEnd(); } else { auto hashTableView = std::dynamic_pointer_cast<const HashTableView<MapType, KeyType> >(groupResults); it1 = hashTableView->getMapBegin(); end = hashTableView->getMapEnd(); } for (it2 = it1; it1 != end; it1 = it2) { // outer loop over unique keys auto pos_list = std::make_shared<pos_list_t>(); for (; (it2 != end) && (it1->first == it2->first); ++it2) { // inner loop, all keys equal to it1->first pos_list->push_back(it2->second); } writeGroupResult(resultTab, pos_list, row); row++; } this->addResult(resultTab); }
void PipeliningHashProbe::fetchPositions() { const auto& probeTable = getProbeTable(); const auto& hash_table = std::dynamic_pointer_cast<const HashTable>(getInputHashTable(0)); assert(hash_table != nullptr); LOG4CXX_DEBUG(logger, hash_table->stats()); LOG4CXX_DEBUG(logger, "Probe Table Size: " << probeTable->size()); LOG4CXX_DEBUG(logger, "Hash Table Size: " << hash_table->size()); for (pos_t probeTableRow = 0; probeTableRow < probeTable->size(); ++probeTableRow) { pos_list_t matchingRows(hash_table->get(probeTable, _field_definition, probeTableRow)); if (!matchingRows.empty()) { _buildTablePosList->insert(_buildTablePosList->end(), matchingRows.begin(), matchingRows.end()); _probeTablePosList->insert(_probeTablePosList->end(), matchingRows.size(), probeTableRow); } // We can only monitor the size of the output after each row has been probed. // Each probed row can produce n matches. The output table will increase by those n rows. // As soon as the current n causes the output table to reach the _chunkSize threshold, // we will emit a chunk and reset the _buildTablePosList and _probeTablePosList. if (_buildTablePosList->size() > _chunkSize) { emitChunk(); } } // Emit final results. if (_buildTablePosList->size() > 0) { emitChunk(); } LOG4CXX_DEBUG(logger, "Done Probing"); }
void HashJoinProbe::fetchPositions(storage::pos_list_t* buildTablePosList, storage::pos_list_t* probeTablePosList) { const auto& probeTable = getProbeTable(); const auto& hash_table = std::dynamic_pointer_cast<const HashTable>(getInputHashTable(0)); assert(hash_table != nullptr); LOG4CXX_DEBUG(logger, hash_table->stats()); LOG4CXX_DEBUG(logger, "Probe Table Size: " << probeTable->size()); LOG4CXX_DEBUG(logger, "Hash Table Size: " << hash_table->size()); for (pos_t probeTableRow = 0; probeTableRow < probeTable->size(); ++probeTableRow) { pos_list_t matchingRows(hash_table->get(probeTable, _field_definition, probeTableRow)); if (!matchingRows.empty()) { buildTablePosList->insert(buildTablePosList->end(), matchingRows.begin(), matchingRows.end()); probeTablePosList->insert(probeTablePosList->end(), matchingRows.size(), probeTableRow); } } LOG4CXX_DEBUG(logger, "Done Probing"); }
void PipeliningHashProbe::setupPlanOperation() { PlanOperation::setupPlanOperation(); setBuildTable(getInputHashTable()->getTable()); }
void HashJoinProbe::setupPlanOperation() { PlanOperation::setupPlanOperation(); setBuildTable(getInputHashTable()->getTable()); }