OmniSciDB  2e3a973ef4
foreign_storage::json_utils Namespace Reference

Functions

void set_value (rapidjson::Value &json_val, const long unsigned int &value, rapidjson::Document::AllocatorType &allocator)
 
void get_value (const rapidjson::Value &json_val, long unsigned int &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)
 
rapidjson::Document read_from_file (const std::string &file_path)
 
void write_to_file (const rapidjson::Document &document, const std::string &filepath)
 
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::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

◆ add_value_to_object()

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

References CHECK, and set_value().

Referenced by foreign_storage::MultiS3Reader::serialize(), foreign_storage::CsvReaderS3::serialize(), foreign_storage::SingleFileReader::serialize(), foreign_storage::CompressedFileReader::serialize(), foreign_storage::MultiFileReader::serialize(), foreign_storage::ParquetDataWrapper::serializeDataWrapperInternals(), foreign_storage::CsvDataWrapper::serializeDataWrapperInternals(), set_value(), and foreign_storage::set_value().

114  {
115  CHECK(object.IsObject());
116  CHECK(!object.HasMember(name));
117  rapidjson::Value json_val;
118  set_value(json_val, value, allocator);
119  rapidjson::Value json_name;
120  json_name.SetString(name, allocator);
121  object.AddMember(json_name, json_val, allocator);
122 }
void set_value(rapidjson::Value &json_val, const std::map< T, V > &map_value, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:82
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_value() [1/5]

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

Definition at line 34 of file FsiJsonUtils.cpp.

References CHECK.

Referenced by get_value(), and get_value_from_object().

34  {
35  CHECK(json_val.IsUint64());
36  value = json_val.GetUint64();
37 }
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ get_value() [2/5]

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

Definition at line 45 of file FsiJsonUtils.cpp.

References CHECK.

45  {
46  CHECK(json_val.IsInt());
47  value = json_val.GetInt();
48 }
#define CHECK(condition)
Definition: Logger.h:197

◆ get_value() [3/5]

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

Definition at line 56 of file FsiJsonUtils.cpp.

References CHECK.

56  {
57  CHECK(json_val.IsString());
58  value = json_val.GetString();
59 }
#define CHECK(condition)
Definition: Logger.h:197

◆ get_value() [4/5]

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

Definition at line 70 of file FsiJsonUtils.h.

References CHECK, and get_value().

70  {
71  CHECK(json_val.IsArray());
72  CHECK(vector_value.size() == 0);
73  for (const auto& json_obj : json_val.GetArray()) {
74  T val;
75  get_value(json_obj, val);
76  vector_value.push_back(val);
77  }
78 }
void get_value(const rapidjson::Value &json_val, std::map< T, V > &map_value)
Definition: FsiJsonUtils.h:96
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:

◆ get_value() [5/5]

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

References CHECK, and get_value_from_object().

96  {
97  CHECK(json_val.IsArray());
98  CHECK(map_value.size() == 0);
99  for (const auto& json_obj : json_val.GetArray()) {
100  CHECK(json_obj.IsObject());
101  T key;
102  V value;
103  get_value_from_object(json_obj, key, "key");
104  get_value_from_object(json_obj, value, "value");
105  map_value[key] = value;
106  }
107 }
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: FsiJsonUtils.h:126
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:

◆ get_value_from_object()

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

References CHECK, get_value(), read_from_file(), and write_to_file().

Referenced by foreign_storage::CompressedFileReader::CompressedFileReader(), foreign_storage::CsvReaderS3::CsvReaderS3(), get_value(), foreign_storage::get_value(), foreign_storage::MultiFileReader::MultiFileReader(), foreign_storage::MultiS3Reader::MultiS3Reader(), foreign_storage::ParquetDataWrapper::restoreDataWrapperInternals(), foreign_storage::CsvDataWrapper::restoreDataWrapperInternals(), and foreign_storage::SingleFileReader::SingleFileReader().

128  {
129  CHECK(object.IsObject());
130  CHECK(object.HasMember(name));
131  get_value(object[name], value);
132 }
void get_value(const rapidjson::Value &json_val, std::map< T, V > &map_value)
Definition: FsiJsonUtils.h:96
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_from_file()

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

Definition at line 61 of file FsiJsonUtils.cpp.

Referenced by get_value_from_object(), foreign_storage::ParquetDataWrapper::restoreDataWrapperInternals(), and foreign_storage::CsvDataWrapper::restoreDataWrapperInternals().

61  {
62  std::ifstream ifs(file_path);
63  if (!ifs) {
64  throw std::runtime_error{"Error trying to open file \"" + file_path +
65  "\". The error was: " + std::strerror(errno)};
66  }
67 
68  rapidjson::IStreamWrapper isw(ifs);
69  rapidjson::Document d;
70  d.ParseStream(isw);
71  return d;
72 }
+ Here is the caller graph for this function:

◆ set_value() [1/5]

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

Definition at line 29 of file FsiJsonUtils.cpp.

Referenced by add_value_to_object(), and set_value().

31  {
32  json_val.SetUint64(value);
33 }
+ Here is the caller graph for this function:

◆ set_value() [2/5]

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

Definition at line 39 of file FsiJsonUtils.cpp.

41  {
42  json_val.SetInt(value);
43 }

◆ set_value() [3/5]

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

Definition at line 50 of file FsiJsonUtils.cpp.

52  {
53  json_val.SetString(value, allocator);
54 }

◆ set_value() [4/5]

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

References set_value().

60  {
61  json_val.SetArray();
62  for (const auto& value : vector_value) {
63  rapidjson::Value json_obj;
64  set_value(json_obj, value, allocator);
65  json_val.PushBack(json_obj, allocator);
66  }
67 }
void set_value(rapidjson::Value &json_val, const std::map< T, V > &map_value, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:82
+ Here is the call graph for this function:

◆ set_value() [5/5]

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

References add_value_to_object().

84  {
85  json_val.SetArray();
86  for (const auto& pair : map_value) {
87  rapidjson::Value pair_obj;
88  pair_obj.SetObject();
89  add_value_to_object(pair_obj, pair.first, "key", allocator);
90  add_value_to_object(pair_obj, pair.second, "value", allocator);
91  json_val.PushBack(pair_obj, allocator);
92  }
93 }
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: FsiJsonUtils.h:111
+ Here is the call graph for this function:

◆ write_to_file()

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

Definition at line 74 of file FsiJsonUtils.cpp.

Referenced by get_value_from_object(), foreign_storage::ParquetDataWrapper::serializeDataWrapperInternals(), and foreign_storage::CsvDataWrapper::serializeDataWrapperInternals().

74  {
75  std::ofstream ofs(filepath);
76  if (!ofs) {
77  throw std::runtime_error{"Error trying to create file \"" + filepath +
78  "\". The error was: " + std::strerror(errno)};
79  }
80  rapidjson::OStreamWrapper osw(ofs);
81  rapidjson::Writer<rapidjson::OStreamWrapper> writer(osw);
82  document.Accept(writer);
83 }
+ Here is the caller graph for this function: