11#include " include/random_nums_config.hpp"
22#include " duckdb/common/string_util.hpp"
3- #include " /Users/zuleykhapavlichenkova/Desktop/duckdb_sqlsmith/duckdb/third_party/yyjson/include/yyjson.hpp"
43#include " duckdb/common/local_file_system.hpp"
54
65#include < iostream>
@@ -32,13 +31,6 @@ void RandomNumsConfig::GetDefaultConfig() {
3231}
3332
3433void RandomNumsConfig::GetConfigFromFile (string &file_path) {
35- // select_percentage = csv_parser(file_path, "select_percentage");
36- // attach_percentage = csv_parser(file_path, "attach_percentage");
37- // attach_use_percentage =csv_parser(file_path, "attach_use_percentage");
38- // detach_percentage =csv_parser(file_path, "detach_percentage");
39- // set_percentage = csv_parser(file_path, "set_percentage");
40- // delete_percentage = csv_parser(file_path, "delete_percentage");
41-
4234 // open and read file into a string &
4335 string result;
4436 std::ifstream open_file (file_path);
@@ -52,66 +44,21 @@ void RandomNumsConfig::GetConfigFromFile(string &file_path) {
5244 }
5345 result.append (line);
5446 }
55- unordered_map<string, string> json;
5647
48+ unordered_map<string, string> json;
5749 try {
5850 json = StringUtil::ParseJSONMap (result);
5951 } catch (std::exception &ex) {
6052 throw IOException (" Couldn't parse JSON file with percentages config." );
6153 }
62-
6354 open_file.close ();
64-
65- std::cout << json[0 ] << std::endl;
66- // LocalFileSystem fs;
67- // string open_file;
68- // try {
69- // auto handle = fs.OpenFile(file_path, FileFlags::FILE_FLAGS_READ);
70- // fs.Read(handle, buffer, n_bites, location);
71-
72-
73-
74- // } catch (std::exception &ex) {
75- // throw IOException("Failed to open config file with provided path '%s.", file_path);
76- // }
77-
78- // read
7955
80-
81-
82- // check the JSON format
83- // if (open_file[0] != '{') {
84- // // throw an error that this is not a JSON
85- // throw IOException("Not JSON file provided as the config.");
86- // }
87- // if (!strstr(open_file, "percentage_types")) {
88- // throw IOException("percentage_types are not provided in the config file.");
89- // }
90-
91- // yyjson_doc *doc = yyjson_read(open_file, strlen(open_file), 0);
92- // if (!doc) {
93- // throw IOException("Failed to read config file with provided path '%s.", file_path);
94- // }
95-
96- // yyjson_val *root = yyjson_doc_get_root(doc);
97- // if (!yyjson_is_obj(root)) {
98- // throw IOException("Not JSON object provided as the config.");
99- // yyjson_doc_free(doc);
100- // }
101-
102- // parse json to map
103- // unordered_map<string, string> json;
104-
105- // try {
106- // json = StringUtil::ParseJSONMap(open_file);
107- // } catch (std::exception &ex) {
108- // throw IOException("Couldn't parse JSON file with percentages config.");
109- // }
56+ select_percentage = stoi (json.find (" select_percentage" )->second );
57+ attach_percentage = stoi (json.find (" attach_percentage" )->second );
58+ attach_use_percentage = stoi (json.find (" attach_use_percentage" )->second );
59+ detach_percentage = stoi (json.find (" detach_percentage" )->second );
60+ set_percentage = stoi (json.find (" set_percentage" )->second );
61+ delete_percentage = stoi (json.find (" delete_percentage" )->second );
11062
11163}
112-
113- // test_yyjson/config.json
114-
115-
116-
117- }
64+ } // namespace duckdb
0 commit comments