inline void operator()() { auto dict = std::dynamic_pointer_cast<BaseDictionary<R>>(table->dictionaryAt(col)); const R* ptr = (R*)(data + sizeof(size_t)); size_t size = *((size_t*)data); // first sizeof(size_t) bytes store dictionary size; dict->reserve(size); for (size_t i = 0; i < size; ++i) { dict->addValue(*(ptr++)); } }
inline void operator()() { auto dict = checked_pointer_cast<ConcurrentUnorderedDictionary<R>>(table->dictionaryAt(col)); size_t size; data.read((char*)&size, sizeof(size_t)); std::vector<R> values(size); data.read((char*)&values[0], size * sizeof(R)); for (const auto value : values) { dict->addValue(value); } }
void SimpleTableDump::dumpDictionary(std::string name, atable_ptr_t table, size_t col, bool delta) { std::string fullPath = _baseDirectory + "/" + name + "/" + table->nameOfColumn(col) + ".dict.dat"; std::ofstream data(fullPath, std::ios::out | std::ios::binary); if (!delta) { // We make a small hack here, first we obtain the size of the // dictionary then we virtually create all value ids, this can break // if the dictionary has no contigous value ids // size_t dictionarySize = table->dictionaryAt(col)->size(); write_to_stream_functor fun(data, table->dictionaryAt(col)); // will pick main dictionary by default for stores type_switch<hyrise_basic_types> ts; ts(table->typeOfColumn(col), fun); /*for(size_t i=0; i < dictionarySize; ++i) { fun.setCol(col); fun.setVid(i); ts(table->typeOfColumn(col), fun); }*/ } else { write_to_stream_functor_delta_dict fun( data, table->dictionaryAt(col)); // will pick main dictionary by default for stores type_switch<hyrise_basic_types> ts; ts(table->typeOfColumn(col), fun); } data.close(); }
void write_to_dict_functor_mmap::operator()<hyrise_string_t>() { auto dict = std::dynamic_pointer_cast<BaseDictionary<hyrise_string_t>>(table->dictionaryAt(col)); size_t size = *((size_t*)data); // first sizeof(size_t) bytes store dictionary size; dict->reserve(size); const size_t* sptr = (size_t*)(data + sizeof(size_t)); const char* cptr = data + 2 * sizeof(size_t); size_t read; for (size_t i = 0; i < size; ++i) { std::string val(cptr, *sptr); dict->addValue(val); read = *sptr; sptr = (size_t*)(cptr + read); cptr = cptr + read + sizeof(size_t); } }
void write_to_delta_vector_functor::operator()<hyrise_string_t>() { auto dict = checked_pointer_cast<ConcurrentUnorderedDictionary<hyrise_string_t>>(table->dictionaryAt(col)); size_t size; // copy whole file to buffer first data.seekg(0, data.end); int length = data.tellg(); data.seekg(0, data.beg); char* buffer = new char[length]; data.read(buffer, length); char* position_in_buffer = buffer; // file's format is (int)nr_of_entries, [(int)length_of_string, string] memcpy(&size, position_in_buffer, sizeof(size_t)); position_in_buffer += sizeof(size_t); for (size_t i = 0; i < size; ++i) { size_t s; memcpy(&s, position_in_buffer, sizeof(size_t)); position_in_buffer += sizeof(size_t); std::string tmp(s, '\0'); memcpy(&tmp[0], position_in_buffer, s); position_in_buffer += s; dict->addValue(tmp); } delete[] buffer; if (position_in_buffer != (buffer + length)) { throw std::runtime_error("Warning, did not read whole file."); } // Equivalent on regular file object, without buffer: // for (size_t i=0; i<size; ++i) { // size_t s; // data.read((char*) &s, sizeof(size_t)); // std::string tmp(s, '\0'); // data.read(&tmp[0], s); // dict->addValue(tmp); // } }