OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
foreign_storage::json_utils Namespace Reference

Functions

std::string get_type_as_string (const rapidjson::Value &object)
 
void set_value (rapidjson::Value &json_val, const size_t &value, rapidjson::Document::AllocatorType &allocator)
 
void get_value (const rapidjson::Value &json_val, size_t &value)
 
void set_value (rapidjson::Value &json_val, const int &value, rapidjson::Document::AllocatorType &allocator)
 
void get_value (const rapidjson::Value &json_val, int &value)
 
void set_value (rapidjson::Value &json_val, const std::string &value, rapidjson::Document::AllocatorType &allocator)
 
void get_value (const rapidjson::Value &json_val, std::string &value)
 
void set_value (rapidjson::Value &json_val, const int64_t &value, rapidjson::Document::AllocatorType &allocator)
 
void get_value (const rapidjson::Value &json_val, int64_t &value)
 
rapidjson::Document read_from_file (const std::string &file_path)
 
void write_to_file (const rapidjson::Document &document, const std::string &filepath)
 
std::string write_to_string (const rapidjson::Document &document)
 
template<class T >
void add_value_to_object (rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
 
template<class T >
void get_value_from_object (const rapidjson::Value &object, T &value, const std::string &name)
 
template<class T >
void set_value (rapidjson::Value &json_val, const std::vector< T > &vector_value, rapidjson::Document::AllocatorType &allocator)
 
template<class T >
void get_value (const rapidjson::Value &json_val, std::vector< T > &vector_value)
 
template<class T , class V >
void set_value (rapidjson::Value &json_val, const std::vector< std::pair< T, V >> &vector_value, rapidjson::Document::AllocatorType &allocator)
 
template<class T , class V >
void get_value (const rapidjson::Value &json_val, std::vector< std::pair< T, V >> &vector_value)
 
template<class T , class V >
void set_value (rapidjson::Value &json_val, const std::map< T, V > &map_value, rapidjson::Document::AllocatorType &allocator)
 
template<class T , class V >
void get_value (const rapidjson::Value &json_val, std::map< T, V > &map_value)
 

Function Documentation

template<class T >
void foreign_storage::json_utils::add_value_to_object ( rapidjson::Value &  object,
const T &  value,
const std::string &  name,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 149 of file FsiJsonUtils.h.

References CHECK, and set_value().

Referenced by foreign_storage::AbstractTextFileDataWrapper::getSerializedDataWrapper(), foreign_storage::ParquetDataWrapper::getSerializedDataWrapper(), foreign_storage::SingleTextFileReader::serialize(), foreign_storage::CompressedFileReader::serialize(), foreign_storage::MultiFileReader::serialize(), foreign_storage::set_value(), and set_value().

152  {
153  CHECK(object.IsObject());
154  CHECK(!object.HasMember(name));
155  rapidjson::Value json_val;
156  set_value(json_val, value, allocator);
157  rapidjson::Value json_name;
158  json_name.SetString(name, allocator);
159  object.AddMember(json_name, json_val, allocator);
160 }
string name
Definition: setup.in.py:72
#define CHECK(condition)
Definition: Logger.h:209
void set_value(rapidjson::Value &json_val, const FileRegion &file_region, rapidjson::Document::AllocatorType &allocator)
Definition: CsvShared.cpp:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string foreign_storage::json_utils::get_type_as_string ( const rapidjson::Value &  object)

Definition at line 30 of file FsiJsonUtils.cpp.

30  {
31  if (object.IsArray()) {
32  return "array";
33  } else if (object.IsBool()) {
34  return "bool";
35  } else if (object.IsDouble()) {
36  return "double";
37  } else if (object.IsFloat()) {
38  return "float";
39  } else if (object.IsInt64()) {
40  return "int64";
41  } else if (object.IsInt()) {
42  return "int";
43  } else if (object.IsNull()) {
44  return "null";
45  } else if (object.IsNumber()) {
46  return "number";
47  } else if (object.IsObject()) {
48  return "onject";
49  } else if (object.IsString()) {
50  return "string";
51  } else if (object.IsUint64()) {
52  return "unit64";
53  } else if (object.IsUint()) {
54  return "unit";
55  }
56  return "unknown";
57 }
void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
size_t &  value 
)

Definition at line 65 of file FsiJsonUtils.cpp.

References CHECK.

Referenced by get_value(), and get_value_from_object().

65  {
66  CHECK(json_val.IsUint64());
67  value = json_val.GetUint64();
68 }
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the caller graph for this function:

void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
int &  value 
)

Definition at line 76 of file FsiJsonUtils.cpp.

References CHECK.

76  {
77  CHECK(json_val.IsInt());
78  value = json_val.GetInt();
79 }
#define CHECK(condition)
Definition: Logger.h:209
template<class T >
void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
std::vector< T > &  vector_value 
)

Definition at line 78 of file FsiJsonUtils.h.

References CHECK, get_value(), and omnisci.dtypes::T.

78  {
79  CHECK(json_val.IsArray());
80  CHECK(vector_value.size() == 0);
81  for (const auto& json_obj : json_val.GetArray()) {
82  T val;
83  get_value(json_obj, val);
84  vector_value.push_back(val);
85  }
86 }
void get_value(const rapidjson::Value &json_val, FileRegion &file_region)
Definition: CsvShared.cpp:44
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
std::string &  value 
)

Definition at line 88 of file FsiJsonUtils.cpp.

References CHECK.

88  {
89  CHECK(json_val.IsString());
90  value = json_val.GetString();
91 }
#define CHECK(condition)
Definition: Logger.h:209
void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
int64_t &  value 
)

Definition at line 99 of file FsiJsonUtils.cpp.

References CHECK.

99  {
100  CHECK(json_val.IsInt64());
101  value = json_val.GetInt64();
102 }
#define CHECK(condition)
Definition: Logger.h:209
template<class T , class V >
void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
std::vector< std::pair< T, V >> &  vector_value 
)

Definition at line 104 of file FsiJsonUtils.h.

References CHECK, get_value_from_object(), and omnisci.dtypes::T.

105  {
106  CHECK(json_val.IsArray());
107  CHECK(vector_value.size() == 0);
108  for (const auto& json_obj : json_val.GetArray()) {
109  CHECK(json_obj.IsObject());
110  T key;
111  V value;
112  get_value_from_object(json_obj, key, "key");
113  get_value_from_object(json_obj, value, "value");
114  vector_value.emplace_back(std::make_pair(key, value));
115  }
116 }
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: FsiJsonUtils.h:164
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

template<class T , class V >
void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
std::map< T, V > &  map_value 
)

Definition at line 134 of file FsiJsonUtils.h.

References CHECK, get_value_from_object(), and omnisci.dtypes::T.

134  {
135  CHECK(json_val.IsArray());
136  CHECK(map_value.size() == 0);
137  for (const auto& json_obj : json_val.GetArray()) {
138  CHECK(json_obj.IsObject());
139  T key;
140  V value;
141  get_value_from_object(json_obj, key, "key");
142  get_value_from_object(json_obj, value, "value");
143  map_value[key] = value;
144  }
145 }
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: FsiJsonUtils.h:164
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

template<class T >
void foreign_storage::json_utils::get_value_from_object ( const rapidjson::Value &  object,
T &  value,
const std::string &  name 
)

Definition at line 164 of file FsiJsonUtils.h.

References CHECK, and get_value().

Referenced by foreign_storage::CompressedFileReader::CompressedFileReader(), foreign_storage::get_value(), get_value(), foreign_storage::MultiFileReader::MultiFileReader(), foreign_storage::AbstractTextFileDataWrapper::restoreDataWrapperInternals(), foreign_storage::ParquetDataWrapper::restoreDataWrapperInternals(), and foreign_storage::SingleTextFileReader::SingleTextFileReader().

166  {
167  CHECK(object.IsObject());
168  CHECK(object.HasMember(name));
169  get_value(object[name], value);
170 }
string name
Definition: setup.in.py:72
void get_value(const rapidjson::Value &json_val, FileRegion &file_region)
Definition: CsvShared.cpp:44
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

rapidjson::Document foreign_storage::json_utils::read_from_file ( const std::string &  file_path)

Definition at line 104 of file FsiJsonUtils.cpp.

Referenced by foreign_storage::AbstractTextFileDataWrapper::restoreDataWrapperInternals(), and foreign_storage::ParquetDataWrapper::restoreDataWrapperInternals().

104  {
105  std::ifstream ifs(file_path);
106  if (!ifs) {
107  throw std::runtime_error{"Error trying to open file \"" + file_path +
108  "\". The error was: " + std::strerror(errno)};
109  }
110 
111  rapidjson::IStreamWrapper isw(ifs);
112  rapidjson::Document d;
113  d.ParseStream(isw);
114  return d;
115 }

+ Here is the caller graph for this function:

void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const size_t &  value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 60 of file FsiJsonUtils.cpp.

Referenced by add_value_to_object(), and set_value().

62  {
63  json_val.SetUint64(value);
64 }

+ Here is the caller graph for this function:

template<class T >
void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const std::vector< T > &  vector_value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 66 of file FsiJsonUtils.h.

References set_value().

68  {
69  json_val.SetArray();
70  for (const auto& value : vector_value) {
71  rapidjson::Value json_obj;
72  set_value(json_obj, value, allocator);
73  json_val.PushBack(json_obj, allocator);
74  }
75 }
void set_value(rapidjson::Value &json_val, const FileRegion &file_region, rapidjson::Document::AllocatorType &allocator)
Definition: CsvShared.cpp:26

+ Here is the call graph for this function:

void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const int &  value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 70 of file FsiJsonUtils.cpp.

72  {
73  json_val.SetInt(value);
74 }
void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const std::string &  value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 81 of file FsiJsonUtils.cpp.

83  {
84  json_val.SetString(value, allocator);
85 }
template<class T , class V >
void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const std::vector< std::pair< T, V >> &  vector_value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 90 of file FsiJsonUtils.h.

References add_value_to_object().

92  {
93  json_val.SetArray();
94  for (const auto& pair : vector_value) {
95  rapidjson::Value pair_obj;
96  pair_obj.SetObject();
97  add_value_to_object(pair_obj, pair.first, "key", allocator);
98  add_value_to_object(pair_obj, pair.second, "value", allocator);
99  json_val.PushBack(pair_obj, allocator);
100  }
101 }
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:149

+ Here is the call graph for this function:

void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const int64_t &  value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 93 of file FsiJsonUtils.cpp.

95  {
96  json_val.SetInt64(value);
97 }
template<class T , class V >
void foreign_storage::json_utils::set_value ( rapidjson::Value &  json_val,
const std::map< T, V > &  map_value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 120 of file FsiJsonUtils.h.

References add_value_to_object().

122  {
123  json_val.SetArray();
124  for (const auto& pair : map_value) {
125  rapidjson::Value pair_obj;
126  pair_obj.SetObject();
127  add_value_to_object(pair_obj, pair.first, "key", allocator);
128  add_value_to_object(pair_obj, pair.second, "value", allocator);
129  json_val.PushBack(pair_obj, allocator);
130  }
131 }
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:149

+ Here is the call graph for this function:

void foreign_storage::json_utils::write_to_file ( const rapidjson::Document &  document,
const std::string &  filepath 
)

Definition at line 117 of file FsiJsonUtils.cpp.

117  {
118  std::ofstream ofs(filepath);
119  if (!ofs) {
120  throw std::runtime_error{"Error trying to create file \"" + filepath +
121  "\". The error was: " + std::strerror(errno)};
122  }
123  rapidjson::OStreamWrapper osw(ofs);
124  rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
125  document.Accept(writer);
126 }
std::string foreign_storage::json_utils::write_to_string ( const rapidjson::Document &  document)

Definition at line 128 of file FsiJsonUtils.cpp.

Referenced by foreign_storage::AbstractTextFileDataWrapper::getSerializedDataWrapper(), and foreign_storage::ParquetDataWrapper::getSerializedDataWrapper().

128  {
129  rapidjson::StringBuffer buffer;
130  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
131  document.Accept(writer);
132  return buffer.GetString();
133 }

+ Here is the caller graph for this function: