Skip to content

Commit

Permalink
Add csv_paths option
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandr Smirnov <[email protected]>
  • Loading branch information
2 people authored and polyntsov committed Nov 24, 2023
1 parent 7b5f86b commit 615ab74
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/core/algorithms/algo_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "algorithms/create_algorithm.h"
#include "algorithms/pipelines/typo_miner/typo_miner.h"
#include "config/names.h"
#include "tabular_data/input_tables_type.h"

namespace algos {

Expand Down Expand Up @@ -71,12 +72,28 @@ template <typename OptionMap>
void LoadAlgorithm(Algorithm& algorithm, OptionMap&& options) {
ConfigureFromFunction(algorithm, [&options](std::string_view option_name) {
using namespace config::names;
namespace fs = std::filesystem;
if (option_name == kTable && options.find(std::string{kTable}) == options.end()) {
config::InputTable parser = std::make_shared<CSVParser>(
details::ExtractOptionValue<std::filesystem::path>(options, kCsvPath),
details::ExtractOptionValue<fs::path>(options, kCsvPath),
details::ExtractOptionValue<char>(options, kSeparator),
details::ExtractOptionValue<bool>(options, kHasHeader));
return boost::any{parser};
} else if (option_name == kTables && options.find(std::string{kTables}) == options.end()) {
auto paths = details::ExtractOptionValue<std::vector<fs::path>>(options, kCsvPaths);
auto separator = details::ExtractOptionValue<char>(options, kSeparator);
auto has_header = details::ExtractOptionValue<bool>(options, kHasHeader);

if (paths.empty()) {
throw config::ConfigurationError("Expected collection of csv paths");
}

config::InputTables tables;
tables.reserve(paths.size());
for (auto const& path : paths) {
tables.push_back(std::make_shared<CSVParser>(path, separator, has_header));
}
return boost::any{tables};
}
return details::GetOrEmpty(options, option_name);
});
Expand Down
3 changes: 2 additions & 1 deletion src/core/config/all_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ boost::program_options::options_description GeneralOptions() {
// clang-format off
po::options_description general_options("General options");
general_options.add_options()
(kCsvPath, po::value<std::filesystem::path>()->required(), kDCsvPath)
(kCsvPath, po::value<std::filesystem::path>(), kDCsvPath)
(kCsvPaths, po::value<std::vector<std::filesystem::path>>(), kDCsvPaths)
(kSeparatorOpt.c_str(), po::value<char>()->default_value(','), kDSeparator)
(kHasHeader, po::value<bool>()->default_value(true), kDHasHeader)
(kEqualNulls, po::value<bool>(), kDEqualNulls)
Expand Down
2 changes: 2 additions & 0 deletions src/core/config/descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace config::descriptions {
constexpr auto kDTable = "table processed by the algorithm";
constexpr auto kDTables = "table collection processed by the algorithm";
constexpr auto kDCsvPath = "path to the CSV table";
constexpr auto kDCsvPaths = "path to the collection of CSV tables";
constexpr auto kDSeparator = "CSV separator";
constexpr auto kDHasHeader = "CSV header presence flag [true|false]";
constexpr auto kDEqualNulls = "specify whether two NULLs should be considered equal";
Expand Down
2 changes: 2 additions & 0 deletions src/core/config/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace config::names {
constexpr auto kTable = "table";
constexpr auto kTables = "tables";
constexpr auto kCsvPath = "csv_path";
constexpr auto kCsvPaths = "csv_paths";
constexpr auto kSeparator = "separator";
constexpr auto kHasHeader = "has_header";
constexpr auto kEqualNulls = "is_null_equal_null";
Expand Down
8 changes: 8 additions & 0 deletions src/core/config/tabular_data/input_tables/option.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "config/tabular_data/input_tables/option.h"

#include "config/names_and_descriptions.h"

namespace config {
using names::kTables, descriptions::kDTables;
extern const CommonOption<InputTables> TablesOpt{kTables, kDTables};
} // namespace config
8 changes: 8 additions & 0 deletions src/core/config/tabular_data/input_tables/option.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "config/common_option.h"
#include "config/tabular_data/input_tables_type.h"

namespace config {
extern const CommonOption<InputTables> TablesOpt;
} // namespace config
9 changes: 9 additions & 0 deletions src/core/config/tabular_data/input_tables_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <vector>

#include "input_table_type.h"

namespace config {
using InputTables = std::vector<InputTable>;
} // namespace config

0 comments on commit 615ab74

Please sign in to comment.