Skip to content

Commit

Permalink
build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpuwa committed May 17, 2024
1 parent 3b9e7e3 commit aec1696
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 63 deletions.
7 changes: 4 additions & 3 deletions src/core/algorithms/dynamic/demo/demo_algo.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "demo_algo.h"
#include "config/names.h"

#include "config/ioption.h"
#include "config/names.h"

using config::names::kTable;
using config::InputTable;
using config::names::kTable;

algos::DynamicAlgorithmDemo::DynamicAlgorithmDemo(std::vector<std::string_view> phase_names)
: DynamicAlgorithm(phase_names) {}
Expand Down Expand Up @@ -41,6 +42,6 @@ std::vector<std::string> algos::DynamicAlgorithmDemo::GetResult() {
}

std::pair<std::vector<std::string>, std::vector<std::string>>
algos::DynamicAlgorithmDemo::GetResultDiff() {
algos::DynamicAlgorithmDemo::GetResultDiff() {
return std::make_pair(added_to_result_.AsStringVector(), erased_from_result_.AsStringVector());
}
50 changes: 16 additions & 34 deletions src/core/algorithms/dynamic/dynamic_algorithm.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
#include "dynamic_algorithm.h"
#include "config/tabular_data/input_table_type.h"
#include "config/names_and_descriptions.h"
#include "config/option_using.h"
#include "config/tabular_data/input_table/option.h"
#include "config/tabular_data/crud_operations/operations.h"

#include <easylogging++.h>

#include "config/names_and_descriptions.h"
#include "config/option_using.h"
#include "config/tabular_data/crud_operations/operations.h"
#include "config/tabular_data/input_table/option.h"
#include "config/tabular_data/input_table_type.h"

namespace {
using config::InputTable;

std::unordered_map<std::string, size_t> GetIndexes(const InputTable& table) {
std::unordered_map<std::string, size_t> index;
for (int i = 0; i < table->GetNumberOfColumns(); ++i) {
index[table->GetColumnName(i)] = i;
}
return std::move(index);
}

std::vector<size_t> GetTransposition(const InputTable& table, const InputTable& stream) {
static std::unordered_map<std::string, size_t> index = GetIndexes(table);
std::vector<size_t> result;
for (int i = 0; i < stream->GetNumberOfColumns(); ++i) {
result.emplace_back(index[stream->GetColumnName(i)]);
}
return std::move(result);
}
} // namespace

void algos::DynamicAlgorithm::RegisterOptions() {
RegisterOption(config::kTableOpt(&input_table_));
Expand Down Expand Up @@ -73,15 +53,16 @@ void algos::DynamicAlgorithm::ValidateInsertStatements(InputTable& data) {
return;
}
if (data->GetNumberOfColumns() != input_table_->GetNumberOfColumns()) {
throw config::ConfigurationError("Invalid data received: the number of columns in the \
throw config::ConfigurationError(
"Invalid data received: the number of columns in the \
modification statements is different from the table.");
}
while (data->HasNextRow()) {
TableRow row{data->GetNextRow()};
if (row.getData().size() != input_table_->GetNumberOfColumns()) {
LOG(WARNING) << "Unexpected number of columns for a row, skipping (expected "
<< input_table_->GetNumberOfColumns() << ", got "
<< row.getData().size() << ")";
<< input_table_->GetNumberOfColumns() << ", got " << row.getData().size()
<< ")";
continue;
}
insert_statements_.Add(row);
Expand All @@ -92,8 +73,9 @@ void algos::DynamicAlgorithm::ValidateInsertStatements(InputTable& data) {
void algos::DynamicAlgorithm::ValidateDeleteStatements(std::vector<size_t>& data) {
for (size_t rowId : data) {
if (!table_rows_ids_.count(rowId)) {
throw config::ConfigurationError("Invalid data received: the row with " +
std::to_string(rowId) + " does not exist in the table.");
throw config::ConfigurationError("Invalid data received: the row with " +
std::to_string(rowId) +
" does not exist in the table.");
} else {
table_rows_ids_.erase(rowId);
delete_statements_.emplace_back(rowId);
Expand All @@ -107,10 +89,10 @@ void algos::DynamicAlgorithm::ConfigureBatch() {
ValidateDeleteStatements(update_old_batch_);
ValidateInsertStatements(update_new_batch_);
if (insert_statements_.Size() != delete_statements_.size()) {
throw config::ConfigurationError("Invalid data received: number of rows to update: "
+ std::to_string(insert_statements_.Size())
+ ", number of rows to update with: "
+ std::to_string(delete_statements_.size()));
throw config::ConfigurationError(
"Invalid data received: number of rows to update: " +
std::to_string(insert_statements_.Size()) +
", number of rows to update with: " + std::to_string(delete_statements_.size()));
}
// configure insert statements
ValidateInsertStatements(insert_batch_);
Expand Down
2 changes: 1 addition & 1 deletion src/core/algorithms/dynamic/dynamic_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DynamicAlgorithm : public Algorithm {
// update operations stream (new values)
InputTable update_new_batch_;
// stores current table rows ids (after last Execute() method call)
std::unordered_set<size_t> table_rows_ids_ {};
std::unordered_set<size_t> table_rows_ids_{};

private:
void AddSpecificNeededOptions(
Expand Down
6 changes: 4 additions & 2 deletions src/core/config/descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ constexpr auto kDGfdData = "Path to file with GFD";
constexpr auto kDMemLimitMB = "memory limit im MBs";
constexpr auto kDInsertStatements = "Rows to be inserted into the table using the insert operation";
constexpr auto kDDeleteStatements = "Rows to be deleted from the table using the delete operation";
constexpr auto kDUpdateOldStatements = "Rows that need to be replaced in the table using the update operation";
constexpr auto kDUpdateNewStatements = "Rows that need to be used to replace old data in the table using the update operation";
constexpr auto kDUpdateOldStatements =
"Rows that need to be replaced in the table using the update operation";
constexpr auto kDUpdateNewStatements =
"Rows that need to be used to replace old data in the table using the update operation";
constexpr auto kDDifferenceTable = "CSV table containing difference limits for each column";
constexpr auto kDNumRows = "Use only first N rows of the table";
constexpr auto kDNUmColumns = "Use only first N columns of the table";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace config {
using names::kInsertStatements, descriptions::kDInsertStatements;
extern CommonOption<InputTable> const kInsertStatementsOpt = {
kInsertStatements, kDInsertStatements, std::nullopt, nullptr, nullptr};
extern CommonOption<InputTable> const kInsertStatementsOpt = {kInsertStatements, kDInsertStatements,
std::nullopt, nullptr, nullptr};
} // namespace config
9 changes: 4 additions & 5 deletions src/core/config/tabular_data/crud_operations/operations.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include "config/names.h"
#include "delete/option.h"
#include "insert/option.h"
#include "update_new/option.h"
#include "update_old/option.h"
#include "config/names.h"

const std::vector<std::string_view> CRUD_OPTIONS{config::names::kInsertStatements,
config::names::kDeleteStatements,
config::names::kUpdateOldStatements,
config::names::kUpdateNewStatements};
const std::vector<std::string_view> CRUD_OPTIONS{
config::names::kInsertStatements, config::names::kDeleteStatements,
config::names::kUpdateOldStatements, config::names::kUpdateNewStatements};

23 changes: 12 additions & 11 deletions src/core/model/table/table_row.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <unordered_set>
#include <utility>

#include <boost/algorithm/string/join.hpp>

#include "column_index.h"
Expand All @@ -22,21 +23,22 @@ class TableRow {
}

public:
TableRow(std::vector<std::string>&& data) :
data_(std::move(data)),
id_(createId()) {}
TableRow(std::vector<std::string>&& data) : data_(std::move(data)), id_(createId()) {}
TableRow(size_t id) : data_({}), id_(id) {}
TableRow() : data_({}), id_(0) {};
TableRow() : data_({}), id_(0){};

TableRow(const TableRow& other) : data_(other.data_), id_(other.id_) {}

TableRow(TableRow&& other) : data_(std::move(other.data_)), id_(other.id_) {}

TableRow& operator=(const TableRow& other) {
if (this != &other) {
data_ = other.data_;
id_ = other.id_;
}
return *this;
}

TableRow& operator=(TableRow&& other) {
if (this != &other) {
data_ = std::move(other.data_);
Expand All @@ -50,7 +52,8 @@ class TableRow {
}

std::string toString() const {
return "(id: " + std::to_string(id_) + ", data: " + boost::algorithm::join(data_, ",") + ")";
return "(id: " + std::to_string(id_) + ", data: " + boost::algorithm::join(data_, ",") +
")";
}

explicit operator std::string() const {
Expand All @@ -61,16 +64,14 @@ class TableRow {
return id_;
}

bool operator==(const TableRow &rhs) const {
bool operator==(const TableRow& rhs) const {
return id_ == rhs.getId();
}
};

template<>
struct std::hash<TableRow>
{
std::size_t operator()(const TableRow& s) const noexcept
{
template <>
struct std::hash<TableRow> {
std::size_t operator()(const TableRow& s) const noexcept {
return s.getId();
}
};
5 changes: 3 additions & 2 deletions src/core/util/dynamic_collection.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <unordered_set>
#include <mutex>
#include <unordered_set>

#include "primitive_collection.h"

namespace util {
Expand Down Expand Up @@ -55,7 +56,7 @@ class DynamicCollection {

std::vector<std::string> AsStringVector() const noexcept {
std::vector<std::string> result_;
for (const T &item : collection_) {
for (const T& item : collection_) {
result_.emplace_back(std::string(item));
}
return result_;
Expand Down
2 changes: 1 addition & 1 deletion src/python_bindings/dynamic/bind_dynamic_algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <pybind11/stl.h>

#include "algorithms/algo_factory.h"
#include "algorithms/dynamic/dynamic_algorithm.h"
#include "algorithms/dynamic/demo/demo_algo.h"
#include "algorithms/dynamic/dynamic_algorithm.h"
#include "config/names.h"
#include "config/tabular_data/crud_operations/operations.h"
#include "py_util/bind_primitive.h"
Expand Down
4 changes: 2 additions & 2 deletions src/python_bindings/py_util/py_to_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include "config/exceptions.h"
#include "config/tabular_data/input_table_type.h"
#include "config/tabular_data/input_tables_type.h"
#include "model/table/table_row.h"
#include "parser/csv_parser/csv_parser.h"
#include "py_util/create_dataframe_reader.h"
#include "util/enum_to_available_values.h"
#include "model/table/table_row.h"
#include "util/dynamic_collection.h"
#include "util/enum_to_available_values.h"

namespace {

Expand Down

0 comments on commit aec1696

Please sign in to comment.