Exemplo n.º 1
0
TEST_F(TableTests, copy_structure_replacement) {
  auto input = io::Loader::shortcuts::load("test/lin_xxs.tbl", io::Loader::params().setReturnsMutableVerticalTable(true));
  ASSERT_EQ(3u, input->partitionCount());
  auto order_indifferent = [](DataType dt) { return makeDictionary(types::getUnorderedType(dt)); };
  auto order_preserving = [](DataType dt) { return makeDictionary(types::getOrderedType(dt)); };

  auto b = [](std::size_t cols) { return std::make_shared<FixedLengthVector<value_id_t>>(cols, 0); };
  hyrise::storage::atable_ptr_t copy  = input->copy_structure(order_preserving, b); 
  ASSERT_TRUE(std::dynamic_pointer_cast<OrderPreservingDictionary<hyrise_int_t>>(copy->dictionaryAt(0,0)) != nullptr);
  hyrise::storage::atable_ptr_t copy2 = input->copy_structure(order_indifferent, b);
  ASSERT_TRUE(std::dynamic_pointer_cast<OrderIndifferentDictionary<hyrise_int_t>>(copy2->dictionaryAt(0,0)) != nullptr);
}
Exemplo n.º 2
0
void SequentialHeapMerger::mergeValues(const std::vector<c_atable_ptr_t > &input_tables,
                                       atable_ptr_t merged_table,
                                       const column_mapping_t &column_mapping,
                                       const uint64_t newSize,
                                       bool useValid,
                                       const std::vector<bool>& valid) {

  //if (input_tables.size () != 2)
  //  throw std::runtime_error("Merging more than 2 tables is not supported with this merger...");

  std::vector<value_id_mapping_t> mappingPerAtrtibute(input_tables[0]->columnCount());

  for (const auto & kv: column_mapping) {
    const auto &source = kv.first;
    const auto &destination = kv.second;
    switch (merged_table->metadataAt(destination).getType()) {
    case IntegerType:
    case IntegerTypeDelta:
    case IntegerTypeDeltaConcurrent:
      mergeValues<hyrise_int_t>(input_tables, source, merged_table, destination, mappingPerAtrtibute[source], useValid, valid);
    break;
    
    case FloatType:
    case FloatTypeDelta:
    case FloatTypeDeltaConcurrent:
      mergeValues<hyrise_float_t>(input_tables, source, merged_table, destination, mappingPerAtrtibute[source], useValid, valid);
      break;
      
    case StringType:
    case StringTypeDelta:
    case StringTypeDeltaConcurrent:
      mergeValues<hyrise_string_t>(input_tables, source, merged_table, destination, mappingPerAtrtibute[source], useValid, valid);
      break;
    case IntegerNoDictType:
    case FloatNoDictType:
      merged_table->setDictionaryAt(makeDictionary(merged_table->typeOfColumn(destination)), destination);
    default:
      break;
    }
  }

  merged_table->resize(newSize);

  // Only after the dictionaries are merged copy the values
  for (const auto & kv: column_mapping) {
    const auto &source = kv.first;
    const auto &destination = kv.second;
    // copy the actual values and apply mapping
    copyValues(input_tables, source, merged_table, destination, mappingPerAtrtibute[source], useValid, valid);
  }
}
Exemplo n.º 3
0
atable_ptr_t AbstractTable::copy_structure_modifiable(const field_list_t *fields, const size_t initial_size, const bool with_containers) const {
  std::vector<ColumnMetadata > metadata;
  auto dictionaries = std::unique_ptr<std::vector<AbstractTable::SharedDictionaryPtr > >(new std::vector<AbstractTable::SharedDictionaryPtr >);

  if (fields != nullptr) {
    for (const field_t & field: *fields) {
      auto m = metadataAt(field);
      m.setType(types::getUnorderedType(m.getType()));
      metadata.push_back(m);
      dictionaries->push_back(makeDictionary(m));
    }
  } else {
    for (size_t i = 0; i < columnCount(); ++i) {
      auto m = metadataAt(i);
      m.setType(types::getUnorderedType(m.getType()));
      metadata.push_back(m);
      dictionaries->push_back(makeDictionary(m));
    }
  }


  auto result = std::make_shared<Table>(&metadata, dictionaries.get(), initial_size, false);
  return result;
}
Exemplo n.º 4
0
atable_ptr_t Table::copy_structure_common(const std::vector<size_t>& fields_to_copy,
                                          size_t initial_size,
                                          DICTIONARY_FLAG dictionary_policy,
                                          COMPRESSION_FLAG compression,
                                          CONCURRENCY_FLAG concurrency) const {
  std::vector<ColumnMetadata> metadata;
  std::vector<adict_ptr_t> dictionaries;
  for (const auto& field : fields_to_copy) {
    metadata.push_back(_metadata.at(field));
    dictionaries.push_back(dictionary_policy == DICTIONARY_FLAG::REUSE ? _dictionaries.at(field)
                                                                       : makeDictionary(_metadata.at(field).getType()));
  }

  auto values = create_attribute_vector(fields_to_copy.size(), initial_size, concurrency, compression, dictionaries);
  return std::make_shared<Table>(metadata, checked_pointer_cast<BaseAttributeVector<value_id_t>>(values), dictionaries);
}
Exemplo n.º 5
0
atable_ptr_t TableBuilder::createTable(param_list::param_list_t::const_iterator begin,
                                       param_list::param_list_t::const_iterator end,
                                       const bool compressed) {
  // Meta data container
  std::vector<ColumnMetadata> vc;
  std::vector<adict_ptr_t> vd;

  for (; begin != end; ++begin) {
    vc.push_back(ColumnMetadata::metadataFromString((*begin).type, (*begin).name));
    vd.push_back(makeDictionary(vc.back().getType()));
  }

  auto tmp = std::make_shared<Table>(&vc, &vd, 0, 0, compressed);

  return tmp;
}
Exemplo n.º 6
0
Table::Table(std::vector<ColumnMetadata>* m,
             std::vector<SharedDictionary>* d,
             size_t initial_size,
             bool sorted,
             bool compressed,
             const std::string& tableName)
    : _metadata(m->size()), _dictionaries(m->size()), width(m->size()), _compressed(compressed) {
  // Ownership change for meta data
  for (size_t i = 0; i < width; i++) {
    _metadata[i] = m->at(i);
  }

  // If we pass dictionaries, reuses them
  if (d) {
    std::copy(d->begin(), d->end(), _dictionaries.begin());
  } else {

    // Otheriwse create new dictionaries based on the met data
    _dictionaries.resize(width);

    // Only create dictionaries if they can be used, sorted dictionaries
    // for empty tables is not useful
    if (!sorted) {
      for (size_t i = 0; i < width; i++) {
        _dictionaries[i] = makeDictionary(_metadata[i].getType(), initial_size);
      }
    }
  }

  std::string id;

  /** Build the attribute vector */
  if (!sorted) {
    if (m->size() == 1) {
      id = tableName + "__delta_col__" + m->at(0).getName();
    }
    tuples = create_attribute_vector(
        width, initial_size, CONCURRENCY_FLAG::CONCURRENT, COMPRESSION_FLAG::UNCOMPRESSED, _dictionaries);
  } else {
    if (m->size() == 1) {
      id = tableName + "__main_col__" + m->at(0).getName();
    }
    tuples = create_attribute_vector(
        width, initial_size, CONCURRENCY_FLAG::NOT_CONCURRENT, COMPRESSION_FLAG::UNCOMPRESSED, _dictionaries);
  }
}