void PosUpdateScan::executePlanOperation() { auto c_pc = checked_pointer_cast<const PointerCalculator>(input.getTable(0)); auto c_store = checked_pointer_cast<const storage::Store>(c_pc->getActualTable()); // Cast the constness away auto store = std::const_pointer_cast<storage::Store>(c_store); // Get the current maximum size const auto& beforSize = store->size(); // Get the offset for inserts into the delta and the size of the delta that // we need to increase by the positions we are inserting auto writeArea = store->appendToDelta(c_pc->getPositions()->size()); // Get the modification record for the current transaction auto& txmgr = tx::TransactionManager::getInstance(); auto& modRecord = txmgr[_txContext.tid]; // Functor we use for updating the data set_json_value_functor fun(store->getDeltaTable()); storage::type_switch<hyrise_basic_types> ts; size_t counter = 0; for(const auto& p : *(c_pc->getPositions())) { // First delete the old record bool deleteOk = store->markForDeletion(p, _txContext.tid) == hyrise::tx::TX_CODE::TX_OK; if(!deleteOk) { txmgr.rollbackTransaction(_txContext); throw std::runtime_error("Aborted TX because TID of other TX found"); } modRecord.deletePos(store, p); //store->setTid(p, _txContext.tid); // Copy the old row from the main store->copyRowToDelta(store, p, writeArea.first+counter, _txContext.tid); // Update all the necessary values for(const auto& kv : _raw_data) { const auto& fld = store->numberOfColumn(kv.first); fun.set(fld, writeArea.first+counter, kv.second); ts(store->typeOfColumn(fld), fun); } // Insert the new one modRecord.insertPos(store, beforSize+counter); ++counter; } // Update affected rows auto rsp = getResponseTask(); if (rsp != nullptr) rsp->incAffectedRows(counter); addResult(c_store); }
TEST_F(MergeTests, store_merge_compex) { auto linxxxs = std::dynamic_pointer_cast<storage::Store>(io::Loader::shortcuts::load("test/lin_xxxs.tbl")); auto ref = std::dynamic_pointer_cast<storage::Store>(io::Loader::shortcuts::load("test/reference/lin_xxxs_update.tbl")); linxxxs->resizeDelta(2); linxxxs->copyRowToDelta(linxxxs, 0, 0, 1); linxxxs->copyRowToDelta(linxxxs, 4, 1, 1); linxxxs->getDeltaTable()->setValue<hyrise_int_t>(1,0,99); linxxxs->getDeltaTable()->setValue<hyrise_int_t>(1,1,99); TableMerger merger(new DefaultMergeStrategy(), new SequentialHeapMerger()); std::vector<hyrise::storage::c_atable_ptr_t> tables; tables.push_back(linxxxs->getMainTable()); tables.push_back(linxxxs->getDeltaTable()); // Valid Vector std::vector<bool> valid = {0,1,1,1,0,1,1}; auto result = merger.merge(tables, true, valid); ASSERT_EQ(5u, result[0]->size()); EXPECT_RELATION_EQ(ref, result[0]); }