OmniSciDB  a987f07e93
 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)
 
std::optional< std::string > get_optional_string_value_from_object (const rapidjson::Value &object, const std::string &key)
 
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 157 of file FsiJsonUtils.h.

References CHECK, setup::name, and set_value().

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

160  {
161  CHECK(object.IsObject());
162  CHECK(!object.HasMember(name)) << "Found unexpected member: " << name;
163  rapidjson::Value json_val;
164  set_value(json_val, value, allocator);
165  rapidjson::Value json_name;
166  json_name.SetString(name, allocator);
167  object.AddMember(json_name, json_val, allocator);
168 }
#define CHECK(condition)
Definition: Logger.h:289
string name
Definition: setup.in.py:72
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::optional< std::string > foreign_storage::json_utils::get_optional_string_value_from_object ( const rapidjson::Value &  object,
const std::string &  key 
)

Definition at line 135 of file FsiJsonUtils.cpp.

Referenced by foreign_storage::anonymous_namespace{InternalCatalogDataWrapper.cpp}::get_data_sources().

137  {
138  if (object.IsObject() && object.HasMember(key) && object[key].IsString()) {
139  return object[key].GetString();
140  }
141  return {};
142 }

+ 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:289

+ 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:289
template<class T >
void foreign_storage::json_utils::get_value ( const rapidjson::Value &  json_val,
std::vector< T > &  vector_value 
)

Definition at line 86 of file FsiJsonUtils.h.

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

86  {
87  CHECK(json_val.IsArray());
88  CHECK(vector_value.size() == 0);
89  for (const auto& json_obj : json_val.GetArray()) {
90  T val;
91  get_value(json_obj, val);
92  vector_value.push_back(val);
93  }
94 }
void get_value(const rapidjson::Value &json_val, FileRegion &file_region)
Definition: CsvShared.cpp:44
#define CHECK(condition)
Definition: Logger.h:289

+ 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:289
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:289
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 112 of file FsiJsonUtils.h.

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

113  {
114  CHECK(json_val.IsArray());
115  CHECK(vector_value.size() == 0);
116  for (const auto& json_obj : json_val.GetArray()) {
117  CHECK(json_obj.IsObject());
118  T key;
119  V value;
120  get_value_from_object(json_obj, key, "key");
121  get_value_from_object(json_obj, value, "value");
122  vector_value.emplace_back(std::make_pair(key, value));
123  }
124 }
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: FsiJsonUtils.h:172
#define CHECK(condition)
Definition: Logger.h:289

+ 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 142 of file FsiJsonUtils.h.

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

142  {
143  CHECK(json_val.IsArray());
144  CHECK(map_value.size() == 0);
145  for (const auto& json_obj : json_val.GetArray()) {
146  CHECK(json_obj.IsObject());
147  T key;
148  V value;
149  get_value_from_object(json_obj, key, "key");
150  get_value_from_object(json_obj, value, "value");
151  map_value[key] = value;
152  }
153 }
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: FsiJsonUtils.h:172
#define CHECK(condition)
Definition: Logger.h:289

+ 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 172 of file FsiJsonUtils.h.

References CHECK, get_value(), and setup::name.

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

174  {
175  CHECK(object.IsObject());
176  CHECK(object.HasMember(name)) << "Could not find member: " << name;
177  get_value(object[name], value);
178 }
void get_value(const rapidjson::Value &json_val, FileRegion &file_region)
Definition: CsvShared.cpp:44
#define CHECK(condition)
Definition: Logger.h:289
string name
Definition: setup.in.py:72

+ 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::ParquetDataWrapper::restoreDataWrapperInternals(), and foreign_storage::AbstractTextFileDataWrapper::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:

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 }
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 74 of file FsiJsonUtils.h.

References set_value().

76  {
77  json_val.SetArray();
78  for (const auto& value : vector_value) {
79  rapidjson::Value json_obj;
80  set_value(json_obj, value, allocator);
81  json_val.PushBack(json_obj, allocator);
82  }
83 }
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 std::string &  value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 81 of file FsiJsonUtils.cpp.

83  {
84  json_val.SetString(value, allocator);
85 }
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::vector< std::pair< T, V >> &  vector_value,
rapidjson::Document::AllocatorType &  allocator 
)

Definition at line 98 of file FsiJsonUtils.h.

References add_value_to_object().

100  {
101  json_val.SetArray();
102  for (const auto& pair : vector_value) {
103  rapidjson::Value pair_obj;
104  pair_obj.SetObject();
105  add_value_to_object(pair_obj, pair.first, "key", allocator);
106  add_value_to_object(pair_obj, pair.second, "value", allocator);
107  json_val.PushBack(pair_obj, allocator);
108  }
109 }
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:157

+ Here is the call graph for this function:

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 128 of file FsiJsonUtils.h.

References add_value_to_object().

130  {
131  json_val.SetArray();
132  for (const auto& pair : map_value) {
133  rapidjson::Value pair_obj;
134  pair_obj.SetObject();
135  add_value_to_object(pair_obj, pair.first, "key", allocator);
136  add_value_to_object(pair_obj, pair.second, "value", allocator);
137  json_val.PushBack(pair_obj, allocator);
138  }
139 }
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:157

+ 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::ParquetDataWrapper::getSerializedDataWrapper(), and foreign_storage::AbstractTextFileDataWrapper::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: