OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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< 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 33 of file StringDictionaryProxy.h.

Constructor & Destructor Documentation

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

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:203
std::string getString(int32_t string_id) const
std::shared_ptr< StringDictionary > string_dict_
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:

StringDictionary * StringDictionaryProxy::getDictionary ( )
noexcept

Definition at line 229 of file StringDictionaryProxy.cpp.

References string_dict_.

229  {
230  return string_dict_.get();
231 }
std::shared_ptr< StringDictionary > string_dict_
ssize_t StringDictionaryProxy::getGeneration ( ) const
noexcept

Definition at line 233 of file StringDictionaryProxy.cpp.

References generation_.

233  {
234  return generation_;
235 }
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(), 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:203
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_mutex rw_mutex_
int32_t truncate_to_generation(const int32_t id, const size_t generation)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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_mutex rw_mutex_
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{StringDictionary.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:203
std::string getString(int32_t string_id) const
std::shared_ptr< StringDictionary > string_dict_
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:

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

Definition at line 205 of file StringDictionaryProxy.cpp.

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:

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().

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:203
static constexpr int32_t INVALID_STR_ID
CHECK(cgen_state)
std::shared_ptr< StringDictionary > string_dict_
std::map< std::string, int32_t > transient_str_to_int_
mapd_shared_mutex rw_mutex_
int32_t truncate_to_generation(const int32_t id, const size_t generation)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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{StringDictionary.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:203
std::string getString(int32_t string_id) const
bool is_regexp_like(const std::string &str, const std::string &pattern, const char escape)
std::shared_ptr< StringDictionary > string_dict_

+ Here is the call graph for this function:

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
CHECK(cgen_state)
std::shared_ptr< StringDictionary > string_dict_
#define CHECK_NE(x, y)
Definition: Logger.h:199
mapd_shared_mutex rw_mutex_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 209 of file StringDictionaryProxy.cpp.

Referenced by string_decompress().

210  {
211  return string_dict_.get()->getStringBytes(string_id);
212 }
std::shared_ptr< StringDictionary > string_dict_

+ Here is the caller graph for this function:

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

Definition at line 59 of file StringDictionaryProxy.h.

References transient_int_to_str_.

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

59  {
60  return transient_int_to_str_;
61  }
std::map< int32_t, std::string > transient_int_to_str_

+ Here is the caller graph for this function:

size_t StringDictionaryProxy::storageEntryCount ( ) const

Definition at line 214 of file StringDictionaryProxy.cpp.

References string_dict_.

214  {
215  return string_dict_.get()->storageEntryCount();
216 }
std::shared_ptr< StringDictionary > string_dict_
void StringDictionaryProxy::updateGeneration ( const ssize_t  generation)
noexcept

Definition at line 218 of file StringDictionaryProxy.cpp.

References CHECK_EQ.

218  {
219  if (generation == -1) {
220  return;
221  }
222  if (generation_ != -1) {
223  CHECK_EQ(generation_, generation);
224  return;
225  }
226  generation_ = generation;
227 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198

Member Data Documentation

ssize_t StringDictionaryProxy::generation_
private
mapd_shared_mutex StringDictionaryProxy::rw_mutex_
mutableprivate
std::shared_ptr<StringDictionary> StringDictionaryProxy::string_dict_
private
std::map<int32_t, std::string> StringDictionaryProxy::transient_int_to_str_
private
std::map<std::string, int32_t> StringDictionaryProxy::transient_str_to_int_
private

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