OmniSciDB  340b00dbf6
 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 int64_t generation)
 
int32_t getOrAdd (const std::string &str) noexcept
 
StringDictionarygetDictionary () noexcept
 
int64_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 int64_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_
 
int64_t generation_
 
mapd_shared_mutex rw_mutex_
 

Detailed Description

Definition at line 29 of file StringDictionaryProxy.h.

Constructor & Destructor Documentation

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

Definition at line 28 of file StringDictionaryProxy.cpp.

30  : 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 167 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().

169  {
170  CHECK_GE(generation_, 0);
171  auto result = string_dict_->getCompare(pattern, comp_operator, generation_);
172  for (const auto& kv : transient_int_to_str_) {
173  const auto str = getString(kv.first);
174  if (do_compare(str, pattern, comp_operator)) {
175  result.push_back(kv.first);
176  }
177  }
178  return result;
179 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
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 234 of file StringDictionaryProxy.cpp.

References string_dict_.

234  {
235  return string_dict_.get();
236 }
std::shared_ptr< StringDictionary > string_dict_
int64_t StringDictionaryProxy::getGeneration ( ) const
noexcept

Definition at line 238 of file StringDictionaryProxy.cpp.

References generation_.

238  {
239  return generation_;
240 }
int32_t StringDictionaryProxy::getIdOfString ( const std::string &  str) const

Definition at line 65 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().

65  {
66  mapd_shared_lock<mapd_shared_mutex> read_lock(rw_mutex_);
68  auto str_id = truncate_to_generation(string_dict_->getIdOfString(str), generation_);
70  return str_id;
71  }
72  auto it = transient_str_to_int_.find(str);
73  return it != transient_str_to_int_.end() ? it->second
75 }
#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_
mapd_shared_lock< mapd_shared_mutex > read_lock
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 77 of file StringDictionaryProxy.cpp.

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

77  {
78  mapd_shared_lock<mapd_shared_mutex> read_lock(rw_mutex_);
79  auto str_id = string_dict_->getIdOfString(str);
81  return str_id;
82  }
83  auto it = transient_str_to_int_.find(str);
84  return it != transient_str_to_int_.end() ? it->second
86 }
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_
std::vector< int32_t > StringDictionaryProxy::getLike ( const std::string &  pattern,
const bool  icase,
const bool  is_simple,
const char  escape 
) const

Definition at line 128 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_.

131  {
132  CHECK_GE(generation_, 0);
133  auto result = string_dict_->getLike(pattern, icase, is_simple, escape, generation_);
134  for (const auto& kv : transient_int_to_str_) {
135  const auto str = getString(kv.first);
136  if (is_like(str, pattern, icase, is_simple, escape)) {
137  result.push_back(kv.first);
138  }
139  }
140  return result;
141 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
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 204 of file StringDictionaryProxy.cpp.

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

204  {
205  return string_dict_->getOrAdd(str);
206 }
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 40 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().

40  {
41  mapd_lock_guard<mapd_shared_mutex> write_lock(rw_mutex_);
43  auto transient_id =
44  truncate_to_generation(string_dict_->getIdOfString(str), generation_);
45  if (transient_id != StringDictionary::INVALID_STR_ID) {
46  return transient_id;
47  }
48  const auto it = transient_str_to_int_.find(str);
49  if (it != transient_str_to_int_.end()) {
50  return it->second;
51  }
52  transient_id =
53  -(transient_str_to_int_.size() + 2); // make sure it's not INVALID_STR_ID
54  {
55  auto it_ok = transient_str_to_int_.insert(std::make_pair(str, transient_id));
56  CHECK(it_ok.second);
57  }
58  {
59  auto it_ok = transient_int_to_str_.insert(std::make_pair(transient_id, str));
60  CHECK(it_ok.second);
61  }
62  return transient_id;
63 }
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_
#define CHECK(condition)
Definition: Logger.h:197
mapd_unique_lock< mapd_shared_mutex > write_lock
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 191 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_.

192  {
193  CHECK_GE(generation_, 0);
194  auto result = string_dict_->getRegexpLike(pattern, escape, generation_);
195  for (const auto& kv : transient_int_to_str_) {
196  const auto str = getString(kv.first);
197  if (is_regexp_like(str, pattern, escape)) {
198  result.push_back(kv.first);
199  }
200  }
201  return result;
202 }
std::map< int32_t, std::string > transient_int_to_str_
#define CHECK_GE(x, y)
Definition: Logger.h:210
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 88 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().

88  {
89  if (inline_int_null_value<int32_t>() == string_id) {
90  return "";
91  }
92  mapd_shared_lock<mapd_shared_mutex> read_lock(rw_mutex_);
93  if (string_id >= 0) {
94  return string_dict_->getString(string_id);
95  }
97  auto it = transient_int_to_str_.find(string_id);
98  CHECK(it != transient_int_to_str_.end());
99  return it->second;
100 }
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:

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

Definition at line 208 of file StringDictionaryProxy.cpp.

References CHECK, CHECK_NE, and StringDictionary::INVALID_STR_ID.

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

209  {
210  if (string_id >= 0) {
211  return string_dict_.get()->getStringBytes(string_id);
212  }
214  auto it = transient_int_to_str_.find(string_id);
215  CHECK(it != transient_int_to_str_.end());
216  return std::make_pair(it->second.c_str(), it->second.size());
217 }
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:

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:

size_t StringDictionaryProxy::storageEntryCount ( ) const

Definition at line 219 of file StringDictionaryProxy.cpp.

References string_dict_.

219  {
220  return string_dict_.get()->storageEntryCount();
221 }
std::shared_ptr< StringDictionary > string_dict_
void StringDictionaryProxy::updateGeneration ( const int64_t  generation)
noexcept

Definition at line 223 of file StringDictionaryProxy.cpp.

References CHECK_EQ.

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

Member Data Documentation

int64_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: