forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_json.cpp
More file actions
33 lines (27 loc) · 861 Bytes
/
complex_json.cpp
File metadata and controls
33 lines (27 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "duckdb/common/complex_json.hpp"
namespace duckdb {
ComplexJSON::ComplexJSON(const string &str) : str_value(str), is_object(false) {
}
ComplexJSON::ComplexJSON() : is_object(false) {
}
void ComplexJSON::AddObject(const string &key, unique_ptr<ComplexJSON> object) {
is_object = true;
obj_value[key] = std::move(object);
}
ComplexJSON &ComplexJSON::GetObject(const string &key) {
if (is_object) {
if (obj_value.find(key) == obj_value.end()) {
throw InvalidInputException("Complex JSON Key not found");
}
return *obj_value[key];
}
throw InvalidInputException("ComplexJson is not an object");
}
unordered_map<string, string> ComplexJSON::Flatten() const {
unordered_map<string, string> result;
for (auto &obj : obj_value) {
result[obj.first] = obj.second->GetValueRecursive(*obj.second);
}
return result;
}
} // namespace duckdb