OmniSciDB  c07336695a
DictionaryValueConverter< TARGET_TYPE > Struct Template Reference

#include <TargetValueConvertersImpl.h>

+ Inheritance diagram for DictionaryValueConverter< TARGET_TYPE >:
+ Collaboration diagram for DictionaryValueConverter< TARGET_TYPE >:

Public Types

using ElementsDataColumnPtr = typename NumericValueConverter< int64_t, TARGET_TYPE >::ColumnDataPtr
 
using ElementsBufferColumnPtr = std::unique_ptr< std::vector< int32_t > >
 
- Public Types inherited from NumericValueConverter< int64_t, TARGET_TYPE >
using ColumnDataPtr = std::unique_ptr< TARGET_TYPE, CheckedMallocDeleter< TARGET_TYPE > >
 
using ElementsBufferColumnPtr = ColumnDataPtr
 

Public Member Functions

 DictionaryValueConverter (const Catalog_Namespace::Catalog &cat, int32_t sourceDictId, const ColumnDescriptor *targetDescriptor, size_t num_rows, TARGET_TYPE nullValue, int64_t nullCheckValue, bool doNullCheck, StringDictionaryProxy *literals_dict)
 
 ~DictionaryValueConverter () override
 
ElementsBufferColumnPtr allocateColumnarBuffer (size_t num_rows)
 
void convertElementToColumnarFormat (size_t row, typename ElementsBufferColumnPtr::pointer columnBuffer, const ScalarTargetValue *scalarValue)
 
void convertToColumnarFormat (size_t row, const ScalarTargetValue *scalarValue)
 
void convertToColumnarFormat (size_t row, const TargetValue *value) override
 
NumericValueConverter< int64_t, TARGET_TYPE >::ColumnDataPtr processBuffer (ElementsBufferColumnPtr buffer)
 
void processArrayBuffer (std::unique_ptr< std::vector< std::pair< size_t, ElementsBufferColumnPtr >>> &array_buffer, std::unique_ptr< std::vector< ArrayDatum >>::pointer arrayData)
 
void finalizeDataBlocksForInsertData () override
 
void addDataBlocksToInsertData (Fragmenter_Namespace::InsertData &insertData) override
 
- Public Member Functions inherited from NumericValueConverter< int64_t, TARGET_TYPE >
 NumericValueConverter (const ColumnDescriptor *cd, size_t num_rows, TARGET_TYPE nullValue, int64_t nullCheckValue, bool doNullCheck)
 
 ~NumericValueConverter () override
 
void allocateColumnarData (size_t num_rows) override
 
ElementsBufferColumnPtr allocateColumnarBuffer (size_t num_rows)
 
void convertElementToColumnarFormat (size_t row, typename ElementsBufferColumnPtr::pointer columnData, const ScalarTargetValue *scalarValue)
 
void convertToColumnarFormat (size_t row, const ScalarTargetValue *scalarValue)
 
void convertToColumnarFormat (size_t row, const TargetValue *value) override
 
void processArrayBuffer (std::unique_ptr< std::vector< std::pair< size_t, ElementsBufferColumnPtr >>> &array_buffer, std::unique_ptr< std::vector< ArrayDatum >>::pointer arrayData)
 
void addDataBlocksToInsertData (Fragmenter_Namespace::InsertData &insertData) override
 
- Public Member Functions inherited from TargetValueConverter
 TargetValueConverter (const ColumnDescriptor *cd)
 
virtual ~TargetValueConverter ()
 

Public Attributes

ElementsBufferColumnPtr column_buffer_
 
const DictDescriptortarget_dict_desc_
 
const DictDescriptorsource_dict_desc_
 
const int32_t buffer_null_sentinal_ = std::numeric_limits<int32_t>::min()
 
const StringDictionaryProxyliterals_dict_
 
std::unordered_map< int32_t, int32_t > literals_lookup_
 
bool use_literals_
 
- Public Attributes inherited from NumericValueConverter< int64_t, TARGET_TYPE >
ColumnDataPtr column_data_
 
TARGET_TYPE null_value_
 
int64_t null_check_value_
 
bool do_null_check_
 
boost_variant_accessor< int64_t > SOURCE_TYPE_ACCESSOR
 
- Public Attributes inherited from TargetValueConverter
const ColumnDescriptorcolumn_descriptor_
 
boost_variant_accessor< ScalarTargetValueSCALAR_TARGET_VALUE_ACCESSOR
 
boost_variant_accessor< ArrayTargetValueARRAY_TARGET_VALUE_ACCESSOR
 
boost_variant_accessor< GeoTargetValueGEO_TARGET_VALUE_ACCESSOR
 
boost_variant_accessor< NullableStringNULLABLE_STRING_ACCESSOR
 
boost_variant_accessor< std::string > STRING_ACCESSOR
 

Detailed Description

template<typename TARGET_TYPE>
struct DictionaryValueConverter< TARGET_TYPE >

Definition at line 120 of file TargetValueConvertersImpl.h.

Member Typedef Documentation

◆ ElementsBufferColumnPtr

template<typename TARGET_TYPE >
using DictionaryValueConverter< TARGET_TYPE >::ElementsBufferColumnPtr = std::unique_ptr<std::vector<int32_t> >

Definition at line 124 of file TargetValueConvertersImpl.h.

◆ ElementsDataColumnPtr

template<typename TARGET_TYPE >
using DictionaryValueConverter< TARGET_TYPE >::ElementsDataColumnPtr = typename NumericValueConverter<int64_t, TARGET_TYPE>::ColumnDataPtr

Definition at line 122 of file TargetValueConvertersImpl.h.

Constructor & Destructor Documentation

◆ DictionaryValueConverter()

template<typename TARGET_TYPE >
DictionaryValueConverter< TARGET_TYPE >::DictionaryValueConverter ( const Catalog_Namespace::Catalog cat,
int32_t  sourceDictId,
const ColumnDescriptor targetDescriptor,
size_t  num_rows,
TARGET_TYPE  nullValue,
int64_t  nullCheckValue,
bool  doNullCheck,
StringDictionaryProxy literals_dict 
)
inline

Definition at line 138 of file TargetValueConvertersImpl.h.

References CHECK, ColumnDescriptor::columnType, SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), Catalog_Namespace::Catalog::getMetadataForDict(), StringDictionaryProxy::getTransientMapping(), and DictDescriptor::stringDict.

147  num_rows,
148  nullValue,
149  nullCheckValue,
150  doNullCheck) {
151  literals_dict_ = literals_dict;
153  cat.getMetadataForDict(targetDescriptor->columnType.get_comp_param(), true);
154 
155  source_dict_desc_ = nullptr;
156 
157  use_literals_ = 0 == sourceDictId;
158  if (!use_literals_) {
159  source_dict_desc_ = cat.getMetadataForDict(std::abs(sourceDictId), true);
161  } else {
162  CHECK(literals_dict);
163 
164  for (auto& entry : literals_dict->getTransientMapping()) {
165  auto newId = target_dict_desc_->stringDict->getOrAdd(entry.second);
166  literals_lookup_[entry.first] = newId;
167  }
168 
170  }
171 
173 
174  if (num_rows) {
176  }
177  }
const int8_t const int64_t * num_rows
const DictDescriptor * source_dict_desc_
ElementsBufferColumnPtr column_buffer_
ElementsBufferColumnPtr allocateColumnarBuffer(size_t num_rows)
const DictDescriptor * target_dict_desc_
const StringDictionaryProxy * literals_dict_
std::shared_ptr< StringDictionary > stringDict
const std::map< int32_t, std::string > getTransientMapping() const
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1348
std::unordered_map< int32_t, int32_t > literals_lookup_
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ ~DictionaryValueConverter()

template<typename TARGET_TYPE >
DictionaryValueConverter< TARGET_TYPE >::~DictionaryValueConverter ( )
inlineoverride

Definition at line 179 of file TargetValueConvertersImpl.h.

179 {}

Member Function Documentation

◆ addDataBlocksToInsertData()

template<typename TARGET_TYPE >
void DictionaryValueConverter< TARGET_TYPE >::addDataBlocksToInsertData ( Fragmenter_Namespace::InsertData insertData)
inlineoverridevirtual

Implements TargetValueConverter.

Definition at line 322 of file TargetValueConvertersImpl.h.

References Fragmenter_Namespace::InsertData::columnIds, Fragmenter_Namespace::InsertData::data, and DataBlockPtr::numbersPtr.

322  {
324  DataBlockPtr dataBlock;
325  dataBlock.numbersPtr = reinterpret_cast<int8_t*>(this->column_data_.get());
326  insertData.data.push_back(dataBlock);
327  insertData.columnIds.push_back(this->column_descriptor_->columnId);
328  }
const ColumnDescriptor * column_descriptor_
void finalizeDataBlocksForInsertData() override
std::vector< DataBlockPtr > data
the number of rows being inserted
Definition: Fragmenter.h:64
int8_t * numbersPtr
Definition: sqltypes.h:137
std::vector< int > columnIds
identifies the table into which the data is being inserted
Definition: Fragmenter.h:62

◆ allocateColumnarBuffer()

template<typename TARGET_TYPE >
ElementsBufferColumnPtr DictionaryValueConverter< TARGET_TYPE >::allocateColumnarBuffer ( size_t  num_rows)
inline

Definition at line 181 of file TargetValueConvertersImpl.h.

References CHECK, and num_rows.

181  {
182  CHECK(num_rows > 0);
183  return std::make_unique<std::vector<int32_t>>(num_rows);
184  }
const int8_t const int64_t * num_rows
#define CHECK(condition)
Definition: Logger.h:187

◆ convertElementToColumnarFormat()

template<typename TARGET_TYPE >
void DictionaryValueConverter< TARGET_TYPE >::convertElementToColumnarFormat ( size_t  row,
typename ElementsBufferColumnPtr::pointer  columnBuffer,
const ScalarTargetValue scalarValue 
)
inline

Definition at line 186 of file TargetValueConvertersImpl.h.

189  {
190  auto mapd_p = checked_get<int64_t>(row, scalarValue, this->SOURCE_TYPE_ACCESSOR);
191  auto val = *mapd_p;
192 
193  if (this->do_null_check_ && this->null_check_value_ == val) {
194  (*columnBuffer)[row] = this->buffer_null_sentinal_;
195  } else {
196  (*columnBuffer)[row] = (int32_t)val;
197  }
198  }
boost_variant_accessor< int64_t > SOURCE_TYPE_ACCESSOR

◆ convertToColumnarFormat() [1/2]

template<typename TARGET_TYPE >
void DictionaryValueConverter< TARGET_TYPE >::convertToColumnarFormat ( size_t  row,
const ScalarTargetValue scalarValue 
)
inline

Definition at line 200 of file TargetValueConvertersImpl.h.

200  {
201  convertElementToColumnarFormat(row, this->column_buffer_.get(), scalarValue);
202  }
ElementsBufferColumnPtr column_buffer_
void convertElementToColumnarFormat(size_t row, typename ElementsBufferColumnPtr::pointer columnBuffer, const ScalarTargetValue *scalarValue)

◆ convertToColumnarFormat() [2/2]

template<typename TARGET_TYPE >
void DictionaryValueConverter< TARGET_TYPE >::convertToColumnarFormat ( size_t  row,
const TargetValue value 
)
inlineoverridevirtual

Implements TargetValueConverter.

Definition at line 204 of file TargetValueConvertersImpl.h.

204  {
205  auto scalarValue =
206  checked_get<ScalarTargetValue>(row, value, this->SCALAR_TARGET_VALUE_ACCESSOR);
207 
208  convertToColumnarFormat(row, scalarValue);
209  }
void convertToColumnarFormat(size_t row, const ScalarTargetValue *scalarValue)
boost_variant_accessor< ScalarTargetValue > SCALAR_TARGET_VALUE_ACCESSOR

◆ finalizeDataBlocksForInsertData()

template<typename TARGET_TYPE >
void DictionaryValueConverter< TARGET_TYPE >::finalizeDataBlocksForInsertData ( )
inlineoverridevirtual

Reimplemented from TargetValueConverter.

Definition at line 315 of file TargetValueConvertersImpl.h.

315  {
316  if (column_buffer_) {
317  this->column_data_ = processBuffer(std::move(column_buffer_));
318  column_buffer_ = nullptr;
319  }
320  }
ElementsBufferColumnPtr column_buffer_
NumericValueConverter< int64_t, TARGET_TYPE >::ColumnDataPtr processBuffer(ElementsBufferColumnPtr buffer)

◆ processArrayBuffer()

template<typename TARGET_TYPE >
void DictionaryValueConverter< TARGET_TYPE >::processArrayBuffer ( std::unique_ptr< std::vector< std::pair< size_t, ElementsBufferColumnPtr >>> &  array_buffer,
std::unique_ptr< std::vector< ArrayDatum >>::pointer  arrayData 
)
inline

Definition at line 268 of file TargetValueConvertersImpl.h.

References anonymous_namespace{TypedDataAccessors.h}::is_null(), StringDictionary::populate_string_array_ids(), and DictDescriptor::stringDict.

271  {
272  if (use_literals_) {
273  for (size_t row = 0; row < array_buffer->size(); row++) {
274  auto& element = (array_buffer->at(row));
275  bool is_null = false;
276  if (element.second) {
278  processBuffer(std::move(element.second));
279  int8_t* arrayDataPtr = reinterpret_cast<int8_t*>(data.release());
280  (*arrayData)[row] =
281  ArrayDatum(element.first * sizeof(TARGET_TYPE), arrayDataPtr, is_null);
282  }
283  }
284  } else {
285  std::vector<std::vector<int32_t>> srcArrayIds(array_buffer->size());
286  std::vector<std::vector<int32_t>> destArrayIds(0);
287 
288  for (size_t row = 0; row < array_buffer->size(); row++) {
289  auto& element = (array_buffer->at(row));
290  if (element.second) {
291  srcArrayIds[row] = *(element.second.get());
292  }
293  }
294 
297  srcArrayIds,
299 
300  for (size_t row = 0; row < array_buffer->size(); row++) {
301  auto& element = (array_buffer->at(row));
302  bool is_null = false;
303  if (element.second) {
304  *(element.second.get()) = destArrayIds[row];
305  int8_t* arrayDataPtr = reinterpret_cast<int8_t*>(&(element.second->at(0)));
306  (*arrayData)[row] = ArrayDatum(element.first * sizeof(TARGET_TYPE),
307  arrayDataPtr,
308  is_null,
309  DoNothingDeleter());
310  }
311  }
312  }
313  }
const DictDescriptor * source_dict_desc_
const DictDescriptor * target_dict_desc_
std::shared_ptr< StringDictionary > stringDict
bool is_null(const T &v, const SQLTypeInfo &t)
static void populate_string_array_ids(std::vector< std::vector< int32_t >> &dest_array_ids, StringDictionary *dest_dict, const std::vector< std::vector< int32_t >> &source_array_ids, const StringDictionary *source_dict)
NumericValueConverter< int64_t, TARGET_TYPE >::ColumnDataPtr processBuffer(ElementsBufferColumnPtr buffer)
std::conditional_t< isCudaCC(), DeviceArrayDatum, HostArrayDatum > ArrayDatum
Definition: sqltypes.h:119
+ Here is the call graph for this function:

◆ processBuffer()

template<typename TARGET_TYPE >
NumericValueConverter<int64_t, TARGET_TYPE>::ColumnDataPtr DictionaryValueConverter< TARGET_TYPE >::processBuffer ( ElementsBufferColumnPtr  buffer)
inline

Definition at line 211 of file TargetValueConvertersImpl.h.

References CHECK, checked_malloc(), DictDescriptor::dictRef, StringDictionary::populate_string_ids(), and DictDescriptor::stringDict.

212  {
215  reinterpret_cast<TARGET_TYPE*>(
216  checked_malloc(buffer->size() * sizeof(TARGET_TYPE))));
217 
218  std::vector<int32_t>* bufferPtr =
219  reinterpret_cast<std::vector<int32_t>*>(buffer.get());
220  TARGET_TYPE* columnDataPtr = reinterpret_cast<TARGET_TYPE*>(data.get());
221  if (use_literals_) {
222  for (size_t i = 0; i < bufferPtr->size(); i++) {
223  auto id = literals_lookup_[(*bufferPtr)[i]];
224  if (id == buffer_null_sentinal_) {
225  columnDataPtr[i] = this->null_value_;
226  } else {
227  columnDataPtr[i] = static_cast<TARGET_TYPE>(id);
228  }
229  }
230  } else {
232  // special case, where source and target dict are the same
233  // mostly in update
234  for (size_t i = 0; i < bufferPtr->size(); i++) {
235  auto src_id = (*bufferPtr)[i];
236  if (src_id == buffer_null_sentinal_) {
237  columnDataPtr[i] = this->null_value_;
238  } else {
239  columnDataPtr[i] = static_cast<TARGET_TYPE>(src_id);
240  }
241  }
242 
243  } else {
244  std::vector<int32_t> dest_ids;
245  dest_ids.resize(bufferPtr->size());
246 
249  *bufferPtr,
251 
252  // fixup NULL sentinel
253  for (size_t i = 0; i < dest_ids.size(); i++) {
254  auto id = dest_ids[i];
255  if (id == buffer_null_sentinal_) {
256  columnDataPtr[i] = this->null_value_;
257  } else {
258  CHECK(std::numeric_limits<TARGET_TYPE>::max() >= id);
259  columnDataPtr[i] = static_cast<TARGET_TYPE>(id);
260  }
261  }
262  }
263  }
264 
265  return data;
266  }
const DictDescriptor * source_dict_desc_
const DictDescriptor * target_dict_desc_
std::shared_ptr< StringDictionary > stringDict
void * checked_malloc(const size_t size)
Definition: checked_alloc.h:40
static void populate_string_ids(std::vector< int32_t > &dest_ids, StringDictionary *dest_dict, const std::vector< int32_t > &source_ids, const StringDictionary *source_dict)
std::unordered_map< int32_t, int32_t > literals_lookup_
#define CHECK(condition)
Definition: Logger.h:187
std::unique_ptr< TARGET_TYPE, CheckedMallocDeleter< TARGET_TYPE > > ColumnDataPtr
+ Here is the call graph for this function:

Member Data Documentation

◆ buffer_null_sentinal_

template<typename TARGET_TYPE >
const int32_t DictionaryValueConverter< TARGET_TYPE >::buffer_null_sentinal_ = std::numeric_limits<int32_t>::min()

Definition at line 131 of file TargetValueConvertersImpl.h.

◆ column_buffer_

template<typename TARGET_TYPE >
ElementsBufferColumnPtr DictionaryValueConverter< TARGET_TYPE >::column_buffer_

Definition at line 126 of file TargetValueConvertersImpl.h.

◆ literals_dict_

template<typename TARGET_TYPE >
const StringDictionaryProxy* DictionaryValueConverter< TARGET_TYPE >::literals_dict_

Definition at line 133 of file TargetValueConvertersImpl.h.

◆ literals_lookup_

template<typename TARGET_TYPE >
std::unordered_map<int32_t, int32_t> DictionaryValueConverter< TARGET_TYPE >::literals_lookup_

Definition at line 135 of file TargetValueConvertersImpl.h.

◆ source_dict_desc_

template<typename TARGET_TYPE >
const DictDescriptor* DictionaryValueConverter< TARGET_TYPE >::source_dict_desc_

Definition at line 129 of file TargetValueConvertersImpl.h.

◆ target_dict_desc_

template<typename TARGET_TYPE >
const DictDescriptor* DictionaryValueConverter< TARGET_TYPE >::target_dict_desc_

Definition at line 128 of file TargetValueConvertersImpl.h.

◆ use_literals_

template<typename TARGET_TYPE >
bool DictionaryValueConverter< TARGET_TYPE >::use_literals_

Definition at line 136 of file TargetValueConvertersImpl.h.


The documentation for this struct was generated from the following file: