Skip to content

Commit 2f3365f

Browse files
committed
change to use enum for file-type and add file_type to JsonParserOption
1 parent 9909190 commit 2f3365f

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

components/core/src/clp_s/CommandLineArguments.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ 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+
std::string file_type;
151152
// clang-format off
152153
compression_options.add_options()(
153154
"compression-level",
@@ -204,9 +205,8 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
204205
"Do not record log order at ingestion time."
205206
)(
206207
"file-type",
207-
po::value<std::string>(&m_file_type)->value_name("FILE_TYPE")->
208-
default_value(m_file_type),
209-
"The type of file that is to be compressed to archive (e.g Json or IR)"
208+
po::value<std::string>(&file_type)->value_name("FILE_TYPE"),
209+
"The type of file that is to be compressed to archive (e.g json or kv-ir)"
210210
);
211211
// clang-format on
212212

@@ -260,6 +260,27 @@ CommandLineArguments::parse_arguments(int argc, char const** argv) {
260260
throw std::invalid_argument("No input paths specified.");
261261
}
262262

263+
constexpr std::string_view cJsonFileType{"json"};
264+
constexpr std::string_view cKeyValueIrFileType{"kv-ir"};
265+
266+
if (parsed_command_line_options.count("file-type") > 0) {
267+
if (cJsonFileType == file_type) {
268+
m_file_type = FileType::Json;
269+
} else if (cKeyValueIrFileType == file_type) {
270+
m_file_type = FileType::KeyValueIr;
271+
if (m_structurize_arrays) {
272+
SPDLOG_ERROR(
273+
"Invalid combination of arguments; --file-type {} and "
274+
"--structurize-arrays can't be used together",
275+
cKeyValueIrFileType
276+
);
277+
return ParsingResult::Failure;
278+
}
279+
} else {
280+
throw std::invalid_argument("Unknown FILE_TYPE: " + file_type);
281+
}
282+
}
283+
263284
// Parse and validate global metadata DB config
264285
if (false == metadata_db_config_file_path.empty()) {
265286
clp::GlobalMetadataDBConfig metadata_db_config;
@@ -814,5 +835,4 @@ void CommandLineArguments::print_search_usage() const {
814835
" [OUTPUT_HANDLER [OUTPUT_HANDLER_OPTIONS]]"
815836
<< std::endl;
816837
}
817-
818838
} // namespace clp_s

components/core/src/clp_s/CommandLineArguments.hpp

Lines changed: 7 additions & 2 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,7 +121,7 @@ class CommandLineArguments {
116121

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

119-
[[nodiscard]] auto get_file_type() const -> std::string { return m_file_type; }
124+
[[nodiscard]] auto get_file_type() const -> FileType { return m_file_type; }
120125

121126
private:
122127
// Methods
@@ -186,7 +191,7 @@ class CommandLineArguments {
186191
size_t m_target_ordered_chunk_size{};
187192
size_t m_minimum_table_size{1ULL * 1024 * 1024}; // 1 MB
188193
bool m_disable_log_order{false};
189-
std::string m_file_type{"Json"};
194+
FileType m_file_type{FileType::Json};
190195

191196
// Metadata db variables
192197
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: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@ bool search_archive(
7272
);
7373

7474
bool compress(CommandLineArguments const& command_line_arguments) {
75-
auto file_type = command_line_arguments.get_file_type();
76-
if ("IR" != file_type && "Json" != file_type) {
77-
SPDLOG_ERROR("File Type specified is Invalid");
78-
return false;
79-
}
80-
if ("IR" == file_type && command_line_arguments.get_structurize_arrays()) {
81-
SPDLOG_ERROR("ERROR: structurized arrays are not supported for IR files");
82-
return false;
83-
}
84-
8575
auto archives_dir = std::filesystem::path(command_line_arguments.get_archives_dir());
8676

8777
// Create output directory in case it doesn't exist
@@ -98,6 +88,7 @@ bool compress(CommandLineArguments const& command_line_arguments) {
9888

9989
clp_s::JsonParserOption option{};
10090
option.file_paths = command_line_arguments.get_file_paths();
91+
option.input_file_type = command_line_arguments.get_file_type();
10192
option.archives_dir = archives_dir.string();
10293
option.target_encoded_size = command_line_arguments.get_target_encoded_size();
10394
option.max_document_size = command_line_arguments.get_max_document_size();
@@ -123,7 +114,7 @@ bool compress(CommandLineArguments const& command_line_arguments) {
123114
}
124115

125116
clp_s::JsonParser parser(option);
126-
if ("IR" == file_type) {
117+
if (CommandLineArguments::FileType::KeyValueIr == option.input_file_type) {
127118
// Functionality Coming in later PR
128119
// -->Call new parsing function in Json Parser to parse IRv2 to archive
129120
// -->Check for error from parsing function

0 commit comments

Comments
 (0)