-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement infrastructure for IND algorithms
Co-authored-by: Chizhov Anton <[email protected]>
- Loading branch information
1 parent
5e37f81
commit de1e33b
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "ind.h" | ||
|
||
#include <sstream> | ||
|
||
namespace model { | ||
|
||
std::string IND::ToString() const { | ||
std::stringstream ss; | ||
ss << GetLhs().ToString() << " -> " << GetRhs().ToString(); | ||
return ss.str(); | ||
} | ||
|
||
} // namespace model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "model/table/column_combination.h" | ||
|
||
namespace model { | ||
|
||
// Inclusion dependency is a relation between attributes of tables | ||
// that indicates possible Primary Key–Foreign Key references. | ||
class IND { | ||
private: | ||
std::shared_ptr<ColumnCombination> lhs_; | ||
std::shared_ptr<ColumnCombination> rhs_; | ||
|
||
public: | ||
IND(std::shared_ptr<ColumnCombination> lhs, std::shared_ptr<ColumnCombination> rhs) | ||
: lhs_(std::move(lhs)), rhs_(std::move(rhs)) {} | ||
|
||
ColumnCombination const& GetLhs() const { | ||
return *lhs_; | ||
} | ||
ColumnCombination const& GetRhs() const { | ||
return *rhs_; | ||
} | ||
std::string ToString() const; | ||
}; | ||
|
||
} // namespace model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "ind_algorithm.h" | ||
|
||
#include "config/names_and_descriptions.h" | ||
#include "config/tabular_data/input_tables/option.h" | ||
|
||
namespace algos { | ||
|
||
INDAlgorithm::INDAlgorithm(std::vector<std::string_view> phase_names) | ||
: Algorithm(std::move(phase_names)) { | ||
RegisterOption(config::TablesOpt(&input_tables_)); | ||
MakeOptionsAvailable({config::TablesOpt.GetName()}); | ||
} | ||
|
||
} // namespace algos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
#include "algorithms/algorithm.h" | ||
#include "ind.h" | ||
#include "tabular_data/input_tables_type.h" | ||
#include "util/primitive_collection.h" | ||
|
||
namespace algos { | ||
|
||
class INDAlgorithm : public Algorithm { | ||
public: | ||
using IND = model::IND; | ||
|
||
private: | ||
util::PrimitiveCollection<IND> ind_collection_; | ||
|
||
void ResetState() final { | ||
ind_collection_.Clear(); | ||
ResetINDAlgorithmState(); | ||
} | ||
|
||
virtual void ResetINDAlgorithmState() = 0; | ||
|
||
protected: | ||
constexpr static std::string_view kDefaultPhaseName = "IND mining"; | ||
|
||
config::InputTables input_tables_; | ||
|
||
explicit INDAlgorithm(std::vector<std::string_view> phase_names); | ||
|
||
virtual void RegisterIND(std::shared_ptr<model::ColumnCombination> lhs, | ||
std::shared_ptr<model::ColumnCombination> rhs) { | ||
ind_collection_.Register(std::move(lhs), std::move(rhs)); | ||
} | ||
virtual void RegisterIND(IND ind) { | ||
ind_collection_.Register(std::move(ind)); | ||
} | ||
|
||
public: | ||
std::list<IND> const& INDList() const noexcept { | ||
return ind_collection_.AsList(); | ||
} | ||
}; | ||
|
||
} // namespace algos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "column_combination.h" | ||
|
||
#include <sstream> | ||
|
||
namespace model { | ||
|
||
std::string ColumnCombination::ToString() const { | ||
std::vector<ColumnIndex> const& col_ids = GetColumnIndices(); | ||
std::stringstream ss; | ||
for (auto it = col_ids.begin(); it != col_ids.end(); ++it) { | ||
if (it != col_ids.begin()) { | ||
ss << ", "; | ||
} | ||
ss << GetTableIndex() << '.' << *it; | ||
} | ||
return ss.str(); | ||
} | ||
|
||
} // namespace model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "column_index.h" | ||
|
||
namespace model { | ||
|
||
// Represents an index for a table within a set of tables | ||
// As an example, this type is used in inclusion dependencies | ||
using TableIndex = unsigned int; | ||
|
||
class ColumnCombination { | ||
protected: | ||
TableIndex table_index_; | ||
std::vector<ColumnIndex> column_indices_; | ||
|
||
public: | ||
ColumnCombination(TableIndex table_index, std::vector<ColumnIndex> col_indices) | ||
: table_index_(table_index), column_indices_(std::move(col_indices)) {} | ||
|
||
TableIndex GetTableIndex() const { | ||
return table_index_; | ||
} | ||
std::vector<ColumnIndex> const& GetColumnIndices() const { | ||
return column_indices_; | ||
} | ||
std::string ToString() const; | ||
}; | ||
|
||
} // namespace model |