Skip to content

Commit

Permalink
parseJSONMap and initialise RandomNumsConfig with the custom values f…
Browse files Browse the repository at this point in the history
…rom the config file
  • Loading branch information
hmeriann committed Sep 12, 2024
1 parent f602008 commit 00d7930
Showing 1 changed file with 8 additions and 60 deletions.
68 changes: 8 additions & 60 deletions src/random_nums_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ void RandomNumsConfig::GetDefaultConfig() {
}

void RandomNumsConfig::GetConfigFromFile(string &file_path) {
// select_percentage = csv_parser(file_path, "select_percentage");
// attach_percentage = csv_parser(file_path, "attach_percentage");
// attach_use_percentage =csv_parser(file_path, "attach_use_percentage");
// detach_percentage =csv_parser(file_path, "detach_percentage");
// set_percentage = csv_parser(file_path, "set_percentage");
// delete_percentage = csv_parser(file_path, "delete_percentage");

// open and read file into a string &
string result;
std::ifstream open_file(file_path);
Expand All @@ -52,66 +45,21 @@ void RandomNumsConfig::GetConfigFromFile(string &file_path) {
}
result.append(line);
}
unordered_map<string, string> json;

unordered_map<string, string> json;
try {
json = StringUtil::ParseJSONMap(result);
} catch (std::exception &ex) {
throw IOException("Couldn't parse JSON file with percentages config.");
}

open_file.close();

std::cout << json[0] << std::endl;
// LocalFileSystem fs;
// string open_file;
// try {
// auto handle = fs.OpenFile(file_path, FileFlags::FILE_FLAGS_READ);
// fs.Read(handle, buffer, n_bites, location);



// } catch (std::exception &ex) {
// throw IOException("Failed to open config file with provided path '%s.", file_path);
// }

//read



// check the JSON format
// if (open_file[0] != '{') {
// // throw an error that this is not a JSON
// throw IOException("Not JSON file provided as the config.");
// }
// if (!strstr(open_file, "percentage_types")) {
// throw IOException("percentage_types are not provided in the config file.");
// }

// yyjson_doc *doc = yyjson_read(open_file, strlen(open_file), 0);
// if (!doc) {
// throw IOException("Failed to read config file with provided path '%s.", file_path);
// }

// yyjson_val *root = yyjson_doc_get_root(doc);
// if (!yyjson_is_obj(root)) {
// throw IOException("Not JSON object provided as the config.");
// yyjson_doc_free(doc);
// }

// parse json to map
// unordered_map<string, string> json;

// try {
// json = StringUtil::ParseJSONMap(open_file);
// } catch (std::exception &ex) {
// throw IOException("Couldn't parse JSON file with percentages config.");
// }
select_percentage = stoi(json.find("select_percentage")->second);
attach_percentage = stoi(json.find("attach_percentage")->second);
attach_use_percentage = stoi(json.find("attach_use_percentage")->second);
detach_percentage = stoi(json.find("detach_percentage")->second);
set_percentage = stoi(json.find("set_percentage")->second);
delete_percentage = stoi(json.find("delete_percentage")->second);

}

// test_yyjson/config.json



}
} // namespace duckdb

0 comments on commit 00d7930

Please sign in to comment.