21 #include <rapidjson/istreamwrapper.h>
22 #include <rapidjson/ostreamwrapper.h>
23 #include <rapidjson/writer.h>
25 #include <rapidjson/stringbuffer.h>
27 namespace json_utils {
30 if (
object.IsArray()) {
32 }
else if (
object.IsBool()) {
34 }
else if (
object.IsDouble()) {
36 }
else if (
object.IsFloat()) {
38 }
else if (
object.IsInt64()) {
40 }
else if (
object.IsInt()) {
42 }
else if (
object.IsNull()) {
44 }
else if (
object.IsNumber()) {
46 }
else if (
object.IsObject()) {
48 }
else if (
object.IsString()) {
50 }
else if (
object.IsUint64()) {
52 }
else if (
object.IsUint()) {
61 rapidjson::Document::AllocatorType& allocator) {
62 json_val.SetUint64(value);
64 void get_value(
const rapidjson::Value& json_val,
size_t& value) {
65 CHECK(json_val.IsUint64());
66 value = json_val.GetUint64();
71 rapidjson::Document::AllocatorType& allocator) {
72 json_val.SetInt(value);
75 void get_value(
const rapidjson::Value& json_val,
int& value) {
76 CHECK(json_val.IsInt());
77 value = json_val.GetInt();
81 const std::string& value,
82 rapidjson::Document::AllocatorType& allocator) {
83 json_val.SetString(value, allocator);
87 void get_value(
const rapidjson::Value& json_val, std::string& value) {
88 CHECK(json_val.IsString());
89 value = json_val.GetString();
94 rapidjson::Document::AllocatorType& allocator) {
95 json_val.SetInt64(value);
98 void get_value(
const rapidjson::Value& json_val, int64_t& value) {
99 CHECK(json_val.IsInt64());
100 value = json_val.GetInt64();
106 rapidjson::Document::AllocatorType& allocator) {
107 json_val.SetBool(value);
110 void get_value(
const rapidjson::Value& json_val,
bool& value) {
111 CHECK(json_val.IsBool());
112 value = json_val.GetBool();
118 rapidjson::Document::AllocatorType& allocator) {
119 json_val.SetInt64(static_cast<int64_t>(value));
123 CHECK(json_val.IsInt64());
124 value =
static_cast<SQLTypes>(json_val.GetInt64());
130 rapidjson::Document::AllocatorType& allocator) {
131 json_val.SetInt64(static_cast<int64_t>(value));
135 CHECK(json_val.IsInt64());
142 rapidjson::Document::AllocatorType& allocator) {
143 json_obj.SetObject();
149 CHECK(json_obj.IsObject());
157 rapidjson::Document::AllocatorType& allocator) {
158 json_val.SetObject();
176 CHECK(json_val.IsObject());
177 get_value_from_object<SQLTypes>(
179 get_value_from_object<SQLTypes>(
181 get_value_from_object<int>(
183 get_value_from_object<int>(
185 get_value_from_object<bool>(
187 get_value_from_object<EncodingType>(
189 get_value_from_object<int>(
191 get_value_from_object<int>(
193 get_value_from_object<shared::StringDictKey>(
202 std::ifstream ifs(file_path);
204 throw std::runtime_error{
"Error trying to open file \"" + file_path +
205 "\". The error was: " + std::strerror(errno)};
208 rapidjson::IStreamWrapper isw(ifs);
209 rapidjson::Document d;
214 void write_to_file(
const rapidjson::Document& document,
const std::string& filepath) {
215 std::ofstream ofs(filepath);
217 throw std::runtime_error{
"Error trying to create file \"" + filepath +
218 "\". The error was: " + std::strerror(errno)};
220 rapidjson::OStreamWrapper osw(ofs);
221 rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
222 document.Accept(writer);
226 rapidjson::StringBuffer buffer;
227 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
228 document.Accept(writer);
229 return buffer.GetString();
233 const rapidjson::Value&
object,
234 const std::string& key) {
235 if (
object.IsObject() &&
object.HasMember(key) &&
object[key].IsString()) {
236 return object[key].GetString();
HOST DEVICE SQLTypes get_subtype() const
void set_compression(EncodingType c)
HOST DEVICE int get_size() const
void set_value(rapidjson::Value &json_val, const ColumnDescriptor &column_desc, rapidjson::Document::AllocatorType &allocator)
const shared::StringDictKey & getStringDictKeySkipCompParamCheck() const
void write_to_file(const rapidjson::Document &document, const std::string &filepath)
HOST DEVICE int get_scale() const
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
HOST DEVICE void set_subtype(SQLTypes st)
HOST DEVICE SQLTypes get_type() const
void setStringDictKeySkipCompParamCheck(const shared::StringDictKey &dict_key)
rapidjson::Document read_from_file(const std::string &file_path)
std::optional< std::string > get_optional_string_value_from_object(const rapidjson::Value &object, const std::string &key)
std::string write_to_string(const rapidjson::Document &document)
void set_comp_param(int p)
std::string get_type_as_string(const rapidjson::Value &object)
HOST DEVICE EncodingType get_compression() const
void get_value(const rapidjson::Value &json_val, ColumnDescriptor &column_desc)
void set_dimension(int d)
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
HOST DEVICE int get_dimension() const
HOST DEVICE int get_comp_param() const
HOST DEVICE bool get_notnull() const
HOST DEVICE void set_type(SQLTypes t)