Skip to content

Commit 2160362

Browse files
authored
feat(clp-s): Add command line options for stubbed out kv-pair-IR ingestion. (#618)
1 parent 60d85d0 commit 2160362

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

components/core/src/clp_s/CommandLineArguments.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
148148
po::options_description compression_options("Compression options");
149149
std::string metadata_db_config_file_path;
150150
std::string input_path_list_file_path;
151+
constexpr std::string_view cJsonFileType{"json"};
152+
constexpr std::string_view cKeyValueIrFileType{"kv-ir"};
153+
std::string file_type{cJsonFileType};
151154
// clang-format off
152155
compression_options.add_options()(
153156
"compression-level",
@@ -202,6 +205,10 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
202205
"disable-log-order",
203206
po::bool_switch(&m_disable_log_order),
204207
"Do not record log order at ingestion time."
208+
)(
209+
"file-type",
210+
po::value<std::string>(&file_type)->value_name("FILE_TYPE")->default_value(file_type),
211+
"The type of file being compressed (json or kv-ir)"
205212
);
206213
// clang-format on
207214

@@ -255,6 +262,22 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
255262
throw std::invalid_argument("No input paths specified.");
256263
}
257264

265+
if (cJsonFileType == file_type) {
266+
m_file_type = FileType::Json;
267+
} else if (cKeyValueIrFileType == file_type) {
268+
m_file_type = FileType::KeyValueIr;
269+
if (m_structurize_arrays) {
270+
SPDLOG_ERROR(
271+
"Invalid combination of arguments; --file-type {} and "
272+
"--structurize-arrays can't be used together",
273+
cKeyValueIrFileType
274+
);
275+
return ParsingResult::Failure;
276+
}
277+
} else {
278+
throw std::invalid_argument("Unknown FILE_TYPE: " + file_type);
279+
}
280+
258281
// Parse and validate global metadata DB config
259282
if (false == metadata_db_config_file_path.empty()) {
260283
clp::GlobalMetadataDBConfig metadata_db_config;

components/core/src/clp_s/CommandLineArguments.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class CommandLineArguments {
3636
Stdout,
3737
};
3838

39+
enum class FileType : uint8_t {
40+
Json = 0,
41+
KeyValueIr
42+
};
43+
3944
// Constructors
4045
explicit CommandLineArguments(std::string const& program_name) : m_program_name(program_name) {}
4146

@@ -116,6 +121,8 @@ class CommandLineArguments {
116121

117122
bool get_record_log_order() const { return false == m_disable_log_order; }
118123

124+
[[nodiscard]] auto get_file_type() const -> FileType { return m_file_type; }
125+
119126
private:
120127
// Methods
121128
/**
@@ -184,6 +191,7 @@ class CommandLineArguments {
184191
size_t m_target_ordered_chunk_size{};
185192
size_t m_minimum_table_size{1ULL * 1024 * 1024}; // 1 MB
186193
bool m_disable_log_order{false};
194+
FileType m_file_type{FileType::Json};
187195

188196
// Metadata db variables
189197
std::optional<clp::GlobalMetadataDBConfig> m_metadata_db_config;

components/core/src/clp_s/JsonParser.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "../clp/GlobalMySQLMetadataDB.hpp"
1414
#include "ArchiveWriter.hpp"
15+
#include "CommandLineArguments.hpp"
1516
#include "DictionaryWriter.hpp"
1617
#include "FileReader.hpp"
1718
#include "FileWriter.hpp"
@@ -29,6 +30,7 @@ using namespace simdjson;
2930
namespace clp_s {
3031
struct JsonParserOption {
3132
std::vector<std::string> file_paths;
33+
CommandLineArguments::FileType input_file_type{CommandLineArguments::FileType::Json};
3234
std::string timestamp_key;
3335
std::string archives_dir;
3436
size_t target_encoded_size{};

components/core/src/clp_s/clp-s.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ bool compress(CommandLineArguments const& command_line_arguments) {
8888

8989
clp_s::JsonParserOption option{};
9090
option.file_paths = command_line_arguments.get_file_paths();
91+
option.input_file_type = command_line_arguments.get_file_type();
9192
option.archives_dir = archives_dir.string();
9293
option.target_encoded_size = command_line_arguments.get_target_encoded_size();
9394
option.max_document_size = command_line_arguments.get_max_document_size();
@@ -113,9 +114,17 @@ bool compress(CommandLineArguments const& command_line_arguments) {
113114
}
114115

115116
clp_s::JsonParser parser(option);
116-
if (false == parser.parse()) {
117-
SPDLOG_ERROR("Encountered error while parsing input");
117+
if (CommandLineArguments::FileType::KeyValueIr == option.input_file_type) {
118+
// Functionality Coming in later PR
119+
// -->Call new parsing function in Json Parser to parse IRv2 to archive
120+
// -->Check for error from parsing function
121+
SPDLOG_ERROR("Compressing Key Value IR Files is not yet supported");
118122
return false;
123+
} else {
124+
if (false == parser.parse()) {
125+
SPDLOG_ERROR("Encountered error while parsing input");
126+
return false;
127+
}
119128
}
120129
parser.store();
121130
return true;

0 commit comments

Comments
 (0)