예제 #1
0
void SimpleTableDump::dumpHeader(std::string name, atable_ptr_t table) {
  std::stringstream header;
  std::vector<std::string> names, types;
  std::vector<uint32_t> parts;

  // Get names and types
  for (size_t i = 0; i < table->columnCount(); ++i) {
    names.push_back(table->nameOfColumn(i));
    types.push_back(data_type_to_string(table->typeOfColumn(i)));
  }

  // This calculation will break if the width of the value_id changes
  // or someone forgets to simply update the width accordingly in the
  // constructor of the table
  for (size_t i = 0; i < table->partitionCount(); ++i) {
    parts.push_back(table->partitionWidth(i));
  }

  // Dump and join
  header << std::accumulate(names.begin(), names.end(), std::string(), infix(" | ")) << "\n";
  header << std::accumulate(types.begin(), types.end(), std::string(), infix(" | ")) << "\n";
  std::vector<std::string> allParts;
  for (size_t i = 0; i < parts.size(); ++i) {
    auto p = parts[i];
    auto tmp = std::vector<std::string>(p, std::to_string(i) + "_R");
    allParts.insert(allParts.end(), tmp.begin(), tmp.end());
  }
  header << std::accumulate(allParts.begin(), allParts.end(), std::string(), infix(" | ")) << "\n";
  header << "===";

  std::string fullPath = _baseDirectory + "/" + name + "/header.dat";
  std::ofstream data(fullPath, std::ios::out | std::ios::binary);
  data << header.str();
  data.close();
}
예제 #2
0
void SimpleTableDump::dumpAttribute(std::string name, atable_ptr_t table, size_t col) {
  assert(std::dynamic_pointer_cast<Store>(table) ==
         nullptr);  // this should never be called with a store directly, but with main and delta table sepratly.
  std::string fullPath = _baseDirectory + "/" + name + "/" + table->nameOfColumn(col) + ".attr.dat";
  std::ofstream data(fullPath, std::ios::out | std::ios::binary);

  // size_t tableSize = table->size(); // get size before, to avoid chasing updates..
  auto tableSize = table->checkpointSize();

  std::vector<value_id_t> vidVector;
  vidVector.resize(tableSize);

  for (size_t i = 0; i < tableSize; ++i) {
    ValueId v;
    v = table->getValueId(col, i);
    vidVector[i] = v.valueId;
  }
  data.write((char*)&vidVector[0], tableSize * sizeof(value_id_t));
  data.close();
}
예제 #3
0
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();
}