From 2528bd5be4632c29705333e4fbbe130c95e257dc Mon Sep 17 00:00:00 2001 From: bastih Date: Mon, 18 Nov 2013 11:44:02 +0100 Subject: [PATCH 1/4] Allow for tuples to be set directly in Table --- src/lib/storage/Table.cpp | 13 +++++++++++++ src/lib/storage/Table.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/lib/storage/Table.cpp b/src/lib/storage/Table.cpp index 1dd834542..bfd6c038f 100644 --- a/src/lib/storage/Table.cpp +++ b/src/lib/storage/Table.cpp @@ -57,6 +57,19 @@ Table::Table( } +Table::Table(std::vector m, + SharedAttributeVector av, + std::vector dicts) : + tuples(av), + _metadata(m.size()), + _dictionaries(dicts), + width(m.size()) { + assert(m.size() == dicts.size() && "Metadata size and dictionaries must match"); + for (size_t i = 0; i < width; i++) { + _metadata[i] = new ColumnMetadata(m.at(i)); + } +} + hyrise::storage::atable_ptr_t Table::copy_structure(const field_list_t *fields, const bool reuse_dict, const size_t initial_size, const bool with_containers, const bool compressed) const { diff --git a/src/lib/storage/Table.h b/src/lib/storage/Table.h index fe5ded5d9..cd1149671 100644 --- a/src/lib/storage/Table.h +++ b/src/lib/storage/Table.h @@ -70,6 +70,10 @@ class Table : public AbstractTable { bool sorted = true, bool compressed = true); + Table(std::vector m, + SharedAttributeVector av, + std::vector dicts); + ~Table(); size_t size() const; From 5f6f48f1be405892893d62d05aed4c12b1687159 Mon Sep 17 00:00:00 2001 From: bastih Date: Mon, 18 Nov 2013 11:45:54 +0100 Subject: [PATCH 2/4] Remove DictionaryFactory in favor of simpler makeDictionary --- src/bin/units_storage/dict_factory.cpp | 13 ++++++++++ src/lib/access/ExpressionScan.cpp | 3 ++- src/lib/access/GroupByScan.cpp | 3 ++- src/lib/access/Layouter.cpp | 14 +++++----- src/lib/storage/AbstractDictionary.h | 31 +--------------------- src/lib/storage/AbstractTable.cpp | 5 ++-- src/lib/storage/DictionaryFactory.h | 36 ++++++++++++++++++++++++++ src/lib/storage/Table.cpp | 14 +++++----- src/lib/storage/TableBuilder.cpp | 3 ++- src/lib/storage/TableGenerator.cpp | 5 ++-- 10 files changed, 77 insertions(+), 50 deletions(-) create mode 100644 src/bin/units_storage/dict_factory.cpp create mode 100644 src/lib/storage/DictionaryFactory.h diff --git a/src/bin/units_storage/dict_factory.cpp b/src/bin/units_storage/dict_factory.cpp new file mode 100644 index 000000000..26f5b550c --- /dev/null +++ b/src/bin/units_storage/dict_factory.cpp @@ -0,0 +1,13 @@ +#include "gtest/gtest.h" + +#include "storage/DictionaryFactory.h" +#include "storage/OrderPreservingDictionary.h" +#include "storage/OrderIndifferentDictionary.h" + +namespace hyrise { namespace storage { + +TEST(factory, creation) { + auto d = makeDictionary(IntegerType, 10); +} + +}} diff --git a/src/lib/access/ExpressionScan.cpp b/src/lib/access/ExpressionScan.cpp index 8a53aaeae..61e589781 100644 --- a/src/lib/access/ExpressionScan.cpp +++ b/src/lib/access/ExpressionScan.cpp @@ -2,6 +2,7 @@ #include "access/ExpressionScan.h" #include "access/system/QueryParser.h" +#include "storage/DictionaryFactory.h" #include "storage/OrderIndifferentDictionary.h" #include "storage/MutableVerticalTable.h" #include "storage/Table.h" @@ -48,7 +49,7 @@ void ExpressionScan::executePlanOperation() { metadata.push_back(m); std::vector dicts; - dicts.push_back(AbstractDictionary::dictionaryWithType>(_expression->getType())); + dicts.push_back(storage::makeDictionary(_expression->getType())); storage::atable_ptr_t exp_result = std::make_shared(&metadata, &dicts, 0, false); exp_result->resize(input_size); diff --git a/src/lib/access/GroupByScan.cpp b/src/lib/access/GroupByScan.cpp index 4878c82cf..a06758fe7 100644 --- a/src/lib/access/GroupByScan.cpp +++ b/src/lib/access/GroupByScan.cpp @@ -3,6 +3,7 @@ #include "access/system/QueryParser.h" #include "storage/ColumnMetadata.h" +#include "storage/DictionaryFactory.h" #include "storage/HashTable.h" #include "storage/PointerCalculator.h" #include "storage/OrderIndifferentDictionary.h" @@ -133,7 +134,7 @@ storage::atable_ptr_t GroupByScan::createResultTableLayout() { for (const auto & fun: _aggregate_functions) { ColumnMetadata *m = new ColumnMetadata(fun->columnName(), fun->getType()); metadata.push_back(m); - dictionaries.push_back(AbstractDictionary::dictionaryWithType >(fun->getType())); + dictionaries.push_back(storage::makeDictionary(fun->getType())); } storage::atable_ptr_t agg_tab = std::make_shared
(&metadata, &dictionaries, 0, false); diff --git a/src/lib/access/Layouter.cpp b/src/lib/access/Layouter.cpp index f8d6909a3..c8f50068b 100644 --- a/src/lib/access/Layouter.cpp +++ b/src/lib/access/Layouter.cpp @@ -2,7 +2,7 @@ #include "access/Layouter.h" #include "access/system/QueryParser.h" - +#include "storage/DictionaryFactory.h" #include "storage/OrderIndifferentDictionary.h" #include "storage/Table.h" @@ -64,12 +64,12 @@ void LayoutSingleTable::executePlanOperation() { std::vector vd; - vd.push_back(DictionaryFactory::build(StringType)); - vd.push_back(DictionaryFactory::build(IntegerType)); - vd.push_back(DictionaryFactory::build(FloatType)); - vd.push_back(DictionaryFactory::build(IntegerType)); - vd.push_back(DictionaryFactory::build(FloatType)); - vd.push_back(DictionaryFactory::build(FloatType)); + vd.push_back(storage::makeDictionary(StringType)); + vd.push_back(storage::makeDictionary(IntegerType)); + vd.push_back(storage::makeDictionary(FloatType)); + vd.push_back(storage::makeDictionary(IntegerType)); + vd.push_back(storage::makeDictionary(FloatType)); + vd.push_back(storage::makeDictionary(FloatType)); // Allocate a new Table result = std::make_shared
(&vc, &vd, _maxResults, false); diff --git a/src/lib/storage/AbstractDictionary.h b/src/lib/storage/AbstractDictionary.h index 48e3120da..433ccf489 100644 --- a/src/lib/storage/AbstractDictionary.h +++ b/src/lib/storage/AbstractDictionary.h @@ -8,30 +8,6 @@ #include "storage/storage_types.h" -class AbstractDictionary; - -template < template class D > -struct DictionaryFactory { - static std::shared_ptr build(DataType type, size_t size = 0) { - switch (type) { - case IntegerType: - return std::make_shared>(size); - break; - - case FloatType: - return std::make_shared>(size); - break; - - case StringType: - return std::make_shared>(size); - break; - - default: - throw std::runtime_error("Type not supported for dictionary"); - } - } -}; - class AbstractDictionary { public: @@ -39,11 +15,6 @@ class AbstractDictionary { virtual bool isOrdered() = 0; - template< class Factory > - static std::shared_ptr dictionaryWithType(DataType type, size_t size = 0) { - return Factory::build(type, size); - } - virtual void reserve(size_t size) = 0; virtual std::shared_ptr copy() = 0; @@ -54,5 +25,5 @@ class AbstractDictionary { }; -#endif // SRC_LIB_STORAGE_ABSTRACTDICTIONARY_H_ +#endif // SRC_LIB_STORAGE_ABSTRACTDICTIONARY_H_ diff --git a/src/lib/storage/AbstractTable.cpp b/src/lib/storage/AbstractTable.cpp index 200a03807..8c558deca 100644 --- a/src/lib/storage/AbstractTable.cpp +++ b/src/lib/storage/AbstractTable.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -58,12 +59,12 @@ hyrise::storage::atable_ptr_t AbstractTable::copy_structure_modifiable(const fie if (fields != nullptr) { for (const field_t & field: *fields) { metadata.push_back(metadataAt(field)); - dictionaries->push_back(AbstractDictionary::dictionaryWithType >(metadataAt(field)->getType())); + dictionaries->push_back(makeDictionary(metadataAt(field)->getType())); } } else { for (size_t i = 0; i < columnCount(); ++i) { metadata.push_back(metadataAt(i)); - dictionaries->push_back(AbstractDictionary::dictionaryWithType >(metadataAt(i)->getType())); + dictionaries->push_back(makeDictionary(metadataAt(i)->getType())); } } diff --git a/src/lib/storage/DictionaryFactory.h b/src/lib/storage/DictionaryFactory.h new file mode 100644 index 000000000..4995f099a --- /dev/null +++ b/src/lib/storage/DictionaryFactory.h @@ -0,0 +1,36 @@ +#ifndef STORAGE_DICTIONARYFACTORY_H_ +#define STORAGE_DICTIONARYFACTORY_H_ + +#include + +#include "storage/AbstractDictionary.h" +#include "storage/meta_storage.h" + +namespace hyrise { namespace storage { namespace detail { + +template