OmniSciDB  8a228a1076
StringDictionaryProxy Class Reference

#include <StringDictionaryProxy.h>

Public Member Functions

 StringDictionaryProxy (std::shared_ptr< StringDictionary > sd, const ssize_t generation)
 
int32_t getOrAdd (const std::string &str) noexcept
 
StringDictionarygetDictionary () noexcept
 
ssize_t getGeneration () const noexcept
 
int32_t getOrAddTransient (const std::string &str)
 
int32_t getIdOfString (const std::string &str) const
 
int32_t getIdOfStringNoGeneration (const std::string &str) const
 
std::string getString (int32_t string_id) const
 
std::pair< const char *, size_t > getStringBytes (int32_t string_id) const noexcept
 
size_t storageEntryCount () const
 
void updateGeneration (const ssize_t generation) noexcept
 
std::vector< int32_t > getLike (const std::string &pattern, const bool icase, const bool is_simple, const char escape) const
 
std::vector< int32_t > getCompare (const std::string &pattern, const std::string &comp_operator) const
 
std::vector< int32_t > getRegexpLike (const std::string &pattern, const char escape) const
 
const std::map< int32_t, std::string > getTransientMapping () const
 

Private Attributes

std::shared_ptr< StringDictionarystring_dict_
 
std::map< int32_t, std::string > transient_int_to_str_
 
std::map< std::string, int32_t > transient_str_to_int_
 
ssize_t generation_
 
mapd_shared_mutex rw_mutex_
 

Detailed Description

Definition at line 29 of file StringDictionaryProxy.h.

Constructor & Destructor Documentation

◆ StringDictionaryProxy()

StringDictionaryProxy::StringDictionaryProxy ( std::shared_ptr< StringDictionary sd,
const ssize_t  generation 
)

Definition at line 29 of file StringDictionaryProxy.cpp.

31  : string_dict_(sd), generation_(generation) {}
std::shared_ptr< StringDictionary > string_dict_

Member Function Documentation

◆ getCompare()

std::vector< int32_t > StringDictionaryProxy::getCompare ( const std::string &  pattern,
const std::string &  comp_operator 
) const

Definition at line 168 of file StringDictionaryProxy.cpp.

References CHECK_GE, anonymous_namespace{StringDictionaryProxy.cpp}::do_compare(), generation_, getString(), run_benchmark_import::result, string_dict_, and transient_int_to_str_.

Referenced by anonymous_namespace{StringOpsIR.cpp}::get_compared_ids().

170  {
171  CHECK_GE(generation_, 0);
172  auto result = string_dict_->getCompare(pattern, comp_operator, generation_);
173  for (const auto& kv : transient_int_to_str_) {
174  const auto str = getString(kv.first);
175  if (do_compare(str, pattern, comp_operator)) {
176  result.push_back(kv.first);
177  }
178  }
179  return result;
180 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
std::shared_ptr< StringDictionary > string_dict_
std::string getString(int32_t string_id) const
bool do_compare(const std::string &str, const std::string &pattern, const std::string &comp_operator)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDictionary()

StringDictionary * StringDictionaryProxy::getDictionary ( )
noexcept

Definition at line 235 of file StringDictionaryProxy.cpp.

References string_dict_.

235  {
236  return string_dict_.get();
237 }
std::shared_ptr< StringDictionary > string_dict_

◆ getGeneration()

ssize_t StringDictionaryProxy::getGeneration ( ) const
noexcept

Definition at line 239 of file StringDictionaryProxy.cpp.

References generation_.

239  {
240  return generation_;
241 }

◆ getIdOfString()

int32_t StringDictionaryProxy::getIdOfString ( const std::string &  str) const

Definition at line 66 of file StringDictionaryProxy.cpp.

References CHECK_GE, generation_, StringDictionary::INVALID_STR_ID, rw_mutex_, string_dict_, transient_str_to_int_, and truncate_to_generation().

Referenced by anonymous_namespace{RelAlgTranslator.cpp}::fill_dictionary_encoded_in_vals(), Executor::serializeLiterals(), and string_compress().

66  {
67  mapd_shared_lock<mapd_shared_mutex> read_lock(rw_mutex_);
69  auto str_id = truncate_to_generation(string_dict_->getIdOfString(str), generation_);
71  return str_id;
72  }
73  auto it = transient_str_to_int_.find(str);
74  return it != transient_str_to_int_.end() ? it->second
76 }
#define CHECK_GE(x, y)
Definition: Logger.h:210
static constexpr int32_t INVALID_STR_ID
std::shared_ptr< StringDictionary > string_dict_
std::map< std::string, int32_t > transient_str_to_int_
int32_t truncate_to_generation(const int32_t id, const size_t generation)
mapd_shared_lock< mapd_shared_mutex > read_lock
mapd_shared_mutex rw_mutex_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIdOfStringNoGeneration()

int32_t StringDictionaryProxy::getIdOfStringNoGeneration ( const std::string &  str) const

Definition at line 78 of file StringDictionaryProxy.cpp.

References StringDictionary::INVALID_STR_ID, rw_mutex_, string_dict_, and transient_str_to_int_.

78  {
79  mapd_shared_lock<mapd_shared_mutex> read_lock(rw_mutex_);
80  auto str_id = string_dict_->getIdOfString(str);
82  return str_id;
83  }
84  auto it = transient_str_to_int_.find(str);
85  return it != transient_str_to_int_.end() ? it->second
87 }
static constexpr int32_t INVALID_STR_ID
std::shared_ptr< StringDictionary > string_dict_
std::map< std::string, int32_t > transient_str_to_int_
mapd_shared_lock< mapd_shared_mutex > read_lock
mapd_shared_mutex rw_mutex_

◆ getLike()

std::vector< int32_t > StringDictionaryProxy::getLike ( const std::string &  pattern,
const bool  icase,
const bool  is_simple,
const char  escape 
) const

Definition at line 129 of file StringDictionaryProxy.cpp.

References CHECK_GE, generation_, getString(), anonymous_namespace{StringDictionaryProxy.cpp}::is_like(), run_benchmark_import::result, string_dict_, and transient_int_to_str_.

132  {
133  CHECK_GE(generation_, 0);
134  auto result = string_dict_->getLike(pattern, icase, is_simple, escape, generation_);
135  for (const auto& kv : transient_int_to_str_) {
136  const auto str = getString(kv.first);
137  if (is_like(str, pattern, icase, is_simple, escape)) {
138  result.push_back(kv.first);
139  }
140  }
141  return result;
142 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
std::shared_ptr< StringDictionary > string_dict_
std::string getString(int32_t string_id) const
bool is_like(const std::string &str, const std::string &pattern, const bool icase, const bool is_simple, const char escape)
+ Here is the call graph for this function:

◆ getOrAdd()

int32_t StringDictionaryProxy::getOrAdd ( const std::string &  str)
noexcept

Definition at line 205 of file StringDictionaryProxy.cpp.

References string_dict_.

Referenced by DictionaryValueConverter< TARGET_TYPE >::convertTransientStringIdToPermanentId().

205  {
206  return string_dict_->getOrAdd(str);
207 }
std::shared_ptr< StringDictionary > string_dict_
+ Here is the caller graph for this function:

◆ getOrAddTransient()

int32_t StringDictionaryProxy::getOrAddTransient ( const std::string &  str)

Definition at line 41 of file StringDictionaryProxy.cpp.

References CHECK, CHECK_GE, generation_, StringDictionary::INVALID_STR_ID, rw_mutex_, string_dict_, transient_int_to_str_, transient_str_to_int_, and truncate_to_generation().

Referenced by lower_encoded(), and Executor::serializeLiterals().

41  {
42  mapd_lock_guard<mapd_shared_mutex> write_lock(rw_mutex_);
44  auto transient_id =
45  truncate_to_generation(string_dict_->getIdOfString(str), generation_);
46  if (transient_id != StringDictionary::INVALID_STR_ID) {
47  return transient_id;
48  }
49  const auto it = transient_str_to_int_.find(str);
50  if (it != transient_str_to_int_.end()) {
51  return it->second;
52  }
53  transient_id =
54  -(transient_str_to_int_.size() + 2); // make sure it's not INVALID_STR_ID
55  {
56  auto it_ok = transient_str_to_int_.insert(std::make_pair(str, transient_id));
57  CHECK(it_ok.second);
58  }
59  {
60  auto it_ok = transient_int_to_str_.insert(std::make_pair(transient_id, str));
61  CHECK(it_ok.second);
62  }
63  return transient_id;
64 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
static constexpr int32_t INVALID_STR_ID
std::shared_ptr< StringDictionary > string_dict_
std::map< std::string, int32_t > transient_str_to_int_
int32_t truncate_to_generation(const int32_t id, const size_t generation)
#define CHECK(condition)
Definition: Logger.h:197
mapd_unique_lock< mapd_shared_mutex > write_lock
mapd_shared_mutex rw_mutex_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRegexpLike()

std::vector< int32_t > StringDictionaryProxy::getRegexpLike ( const std::string &  pattern,
const char  escape 
) const

Definition at line 192 of file StringDictionaryProxy.cpp.

References CHECK_GE, generation_, getString(), anonymous_namespace{StringDictionaryProxy.cpp}::is_regexp_like(), run_benchmark_import::result, string_dict_, and transient_int_to_str_.

193  {
194  CHECK_GE(generation_, 0);
195  auto result = string_dict_->getRegexpLike(pattern, escape, generation_);
196  for (const auto& kv : transient_int_to_str_) {
197  const auto str = getString(kv.first);
198  if (is_regexp_like(str, pattern, escape)) {
199  result.push_back(kv.first);
200  }
201  }
202  return result;
203 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
std::shared_ptr< StringDictionary > string_dict_
std::string getString(int32_t string_id) const
bool is_regexp_like(const std::string &str, const std::string &pattern, const char escape)
+ Here is the call graph for this function:

◆ getString()

std::string StringDictionaryProxy::getString ( int32_t  string_id) const

Definition at line 89 of file StringDictionaryProxy.cpp.

References CHECK, CHECK_NE, StringDictionary::INVALID_STR_ID, rw_mutex_, string_dict_, and transient_int_to_str_.

Referenced by anonymous_namespace{ResultSetIteration.cpp}::build_string_array_target_value(), StringValueConverter::convertToColumnarFormatFromDict(), DictionaryValueConverter< TARGET_TYPE >::convertTransientStringIdToPermanentId(), anonymous_namespace{RelAlgTranslator.cpp}::fill_dictionary_encoded_in_vals(), getCompare(), getLike(), getRegexpLike(), lower_encoded(), GenericKeyHandler::operator()(), and anonymous_namespace{HashJoinRuntime.cpp}::translate_str_id_to_outer_dict().

89  {
90  if (inline_int_null_value<int32_t>() == string_id) {
91  return "";
92  }
93  mapd_shared_lock<mapd_shared_mutex> read_lock(rw_mutex_);
94  if (string_id >= 0) {
95  return string_dict_->getString(string_id);
96  }
98  auto it = transient_int_to_str_.find(string_id);
99  CHECK(it != transient_int_to_str_.end());
100  return it->second;
101 }
std::map< int32_t, std::string > transient_int_to_str_
static constexpr int32_t INVALID_STR_ID
std::shared_ptr< StringDictionary > string_dict_
#define CHECK_NE(x, y)
Definition: Logger.h:206
mapd_shared_lock< mapd_shared_mutex > read_lock
#define CHECK(condition)
Definition: Logger.h:197
mapd_shared_mutex rw_mutex_
+ Here is the caller graph for this function:

◆ getStringBytes()

std::pair< const char *, size_t > StringDictionaryProxy::getStringBytes ( int32_t  string_id) const
noexcept

Definition at line 209 of file StringDictionaryProxy.cpp.

References CHECK, CHECK_NE, StringDictionary::INVALID_STR_ID, string_dict_, and transient_int_to_str_.

Referenced by anonymous_namespace{ExternalExecutor.cpp}::decode_string(), and string_decompress().

210  {
211  if (string_id >= 0) {
212  return string_dict_.get()->getStringBytes(string_id);
213  }
215  auto it = transient_int_to_str_.find(string_id);
216  CHECK(it != transient_int_to_str_.end());
217  return std::make_pair(it->second.c_str(), it->second.size());
218 }
std::map< int32_t, std::string > transient_int_to_str_
static constexpr int32_t INVALID_STR_ID
std::shared_ptr< StringDictionary > string_dict_
#define CHECK_NE(x, y)
Definition: Logger.h:206
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ getTransientMapping()

const std::map<int32_t, std::string> StringDictionaryProxy::getTransientMapping ( ) const
inline

Definition at line 55 of file StringDictionaryProxy.h.

References transient_int_to_str_.

Referenced by DictionaryValueConverter< TARGET_TYPE >::DictionaryValueConverter(), and DictionaryValueConverter< TARGET_TYPE >::processBuffer().

55  {
56  return transient_int_to_str_;
57  }
std::map< int32_t, std::string > transient_int_to_str_
+ Here is the caller graph for this function:

◆ storageEntryCount()

size_t StringDictionaryProxy::storageEntryCount ( ) const

Definition at line 220 of file StringDictionaryProxy.cpp.

References string_dict_.

220  {
221  return string_dict_.get()->storageEntryCount();
222 }
std::shared_ptr< StringDictionary > string_dict_

◆ updateGeneration()

void StringDictionaryProxy::updateGeneration ( const ssize_t  generation)
noexcept

Definition at line 224 of file StringDictionaryProxy.cpp.

References CHECK_EQ, and generation_.

224  {
225  if (generation == -1) {
226  return;
227  }
228  if (generation_ != -1) {
229  CHECK_EQ(generation_, generation);
230  return;
231  }
232  generation_ = generation;
233 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205

Member Data Documentation

◆ generation_

ssize_t StringDictionaryProxy::generation_
private

◆ rw_mutex_

mapd_shared_mutex StringDictionaryProxy::rw_mutex_
mutableprivate

◆ string_dict_

◆ transient_int_to_str_

std::map<int32_t, std::string> StringDictionaryProxy::transient_int_to_str_
private

◆ transient_str_to_int_

std::map<std::string, int32_t> StringDictionaryProxy::transient_str_to_int_
private

The documentation for this class was generated from the following files: