OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
data_conversion::StringViewToArrayEncoder< ScalarEncoderType > Class Template Reference

#include <StringViewToArrayEncoder.h>

+ Inheritance diagram for data_conversion::StringViewToArrayEncoder< ScalarEncoderType >:
+ Collaboration diagram for data_conversion::StringViewToArrayEncoder< ScalarEncoderType >:

Public Types

using DstDataType = typename ScalarEncoderType::DataType
 
- Public Types inherited from data_conversion::TypedBaseConvertEncoder< ScalarEncoderType::DataType, ScalarEncoderType::MetadataType >
using DataType = ScalarEncoderType::DataType
 
using MetadataType = ScalarEncoderType::MetadataType
 

Public Member Functions

 StringViewToArrayEncoder (const Chunk_NS::Chunk &scalar_temp_chunk, const Chunk_NS::Chunk &dst_chunk, const bool error_tracking_enabled)
 
void encodeAndAppendData (const int8_t *data, const size_t num_elements) override
 
void appendArrayDatums (const size_t num_elements, std::optional< std::vector< bool >> &error_occurred, int8_t *current_data, size_t current_scalar_offset)
 
void clearLocalState (const size_t num_elements)
 
void encodeScalarData (const size_t num_elements, const std::string_view *typed_data, const import_export::CopyParams &default_copy_params, std::optional< std::vector< bool >> &error_occurred)
 
- Public Member Functions inherited from data_conversion::TypedBaseConvertEncoder< ScalarEncoderType::DataType, ScalarEncoderType::MetadataType >
 TypedBaseConvertEncoder (const bool error_tracking_enabled)
 
std::shared_ptr< ChunkMetadatagetMetadata (const Chunk_NS::Chunk &chunk) const override
 
- Public Member Functions inherited from data_conversion::BaseConvertEncoder
virtual ~BaseConvertEncoder ()
 
 BaseConvertEncoder (const bool error_tracking_enabled)
 
void initializeDeleteBuffer (const size_t size_hint)
 
virtual void finalize (const size_t rows_appended)
 

Private Member Functions

void initialize ()
 

Private Attributes

SQLTypeInfo dst_type_info_
 
const Chunk_NS::Chunkdst_chunk_
 
const Chunk_NS::Chunkscalar_temp_chunk_
 
AbstractBufferbuffer_
 
ScalarEncoderType scalar_encoder_
 
std::vector< std::string > array_
 
std::vector< std::string_view > array_views_
 
std::vector< ArrayDatumarray_datums_
 
std::vector< size_t > array_sizes_
 
std::vector< bool > is_null_
 

Additional Inherited Members

- Protected Member Functions inherited from data_conversion::TypedBaseConvertEncoder< ScalarEncoderType::DataType, ScalarEncoderType::MetadataType >
DataType getNull () const
 
void updateMetadataStats (const DataType &typed_value, const bool is_date_in_days=false)
 
- Protected Member Functions inherited from data_conversion::BaseConvertEncoder
virtual void clear ()
 
template<typename DataType >
bool isNull (const DataType &typed_value)
 
- Protected Attributes inherited from data_conversion::TypedBaseConvertEncoder< ScalarEncoderType::DataType, ScalarEncoderType::MetadataType >
MetadataType min_
 
MetadataType max_
 
- Protected Attributes inherited from data_conversion::BaseConvertEncoder
std::optional< std::vector
< bool > > 
delete_buffer_
 
const bool error_tracking_enabled_
 
bool has_nulls_
 
size_t num_elements_
 

Detailed Description

template<typename ScalarEncoderType>
class data_conversion::StringViewToArrayEncoder< ScalarEncoderType >

Definition at line 29 of file StringViewToArrayEncoder.h.

Member Typedef Documentation

template<typename ScalarEncoderType >
using data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::DstDataType = typename ScalarEncoderType::DataType

Definition at line 33 of file StringViewToArrayEncoder.h.

Constructor & Destructor Documentation

template<typename ScalarEncoderType >
data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::StringViewToArrayEncoder ( const Chunk_NS::Chunk scalar_temp_chunk,
const Chunk_NS::Chunk dst_chunk,
const bool  error_tracking_enabled 
)
inline

Definition at line 35 of file StringViewToArrayEncoder.h.

References data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::initialize().

38  : TypedBaseConvertEncoder<typename ScalarEncoderType::DataType,
39  typename ScalarEncoderType::MetadataType>(
40  error_tracking_enabled)
41  , dst_chunk_(dst_chunk)
42  , scalar_temp_chunk_(scalar_temp_chunk)
43  , scalar_encoder_(scalar_temp_chunk, error_tracking_enabled) {
44  initialize();
45  }

+ Here is the call graph for this function:

Member Function Documentation

template<typename ScalarEncoderType >
void data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::appendArrayDatums ( const size_t  num_elements,
std::optional< std::vector< bool >> &  error_occurred,
int8_t *  current_data,
size_t  current_scalar_offset 
)
inline

Definition at line 70 of file StringViewToArrayEncoder.h.

References data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_datums_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_sizes_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::buffer_, CHECK, import_export::ImporterUtils::composeNullArray(), data_conversion::BaseConvertEncoder::delete_buffer_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::dst_type_info_, data_conversion::BaseConvertEncoder::error_tracking_enabled_, SQLTypeInfo::get_notnull(), SQLTypeInfo::get_size(), Data_Namespace::AbstractBuffer::getEncoder(), SQLTypeInfo::is_fixlen_array(), data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::is_null_, SQLTypeInfo::is_varlen_array(), data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::scalar_encoder_, to_string(), and UNREACHABLE.

Referenced by data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::encodeAndAppendData().

73  {
74  for (size_t i = 0; i < num_elements; ++i) {
75  auto array_size = array_sizes_[i];
77  BaseConvertEncoder::delete_buffer_->push_back(false);
78  }
79  if (is_null_[i]) {
83  } else {
84  throw std::runtime_error("NULL value not allowed in NOT NULL column");
85  }
86  }
87  array_datums_.push_back(
89  } else {
91  for (size_t j = current_scalar_offset; j < current_scalar_offset + array_size;
92  ++j) {
93  if ((*scalar_encoder_.getDeleteBuffer())[j]) {
94  (*error_occurred)[i] = true;
95  break;
96  }
97  }
98  current_scalar_offset += array_size;
99  }
101  array_size * sizeof(DstDataType) !=
102  static_cast<size_t>(dst_type_info_.get_size())) {
104  array_datums_.push_back(
106  current_data += sizeof(DstDataType) * array_size;
107  BaseConvertEncoder::delete_buffer_->back() = true;
108  continue;
109  } else {
110  throw std::runtime_error(
111  "Incorrect number of elements (" + std::to_string(array_size) +
112  ") in array for fixed length array of size " +
114  }
115  } else {
117  if ((*error_occurred)[i]) {
118  array_datums_.push_back(
120  BaseConvertEncoder::delete_buffer_->back() = true;
121  continue;
122  }
123  }
124  array_datums_.emplace_back(
125  sizeof(DstDataType) * array_size, current_data, false, DoNothingDeleter{});
126  current_data += sizeof(DstDataType) * array_size;
127  }
128  }
129  }
130 
132  auto encoder = dynamic_cast<ArrayNoneEncoder*>(buffer_->getEncoder());
133  CHECK(encoder);
134  encoder->appendData(&array_datums_, 0, num_elements, false);
135  } else if (dst_type_info_.is_fixlen_array()) {
136  auto encoder = dynamic_cast<FixedLengthArrayNoneEncoder*>(buffer_->getEncoder());
137  CHECK(encoder);
138  encoder->appendData(&array_datums_, 0, num_elements, false);
139  } else {
140  UNREACHABLE();
141  }
142  }
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
bool is_varlen_array() const
Definition: sqltypes.h:588
static ArrayDatum composeNullArray(const SQLTypeInfo &ti)
Definition: Importer.cpp:395
#define UNREACHABLE()
Definition: Logger.h:338
std::string to_string(char const *&&v)
bool is_fixlen_array() const
Definition: sqltypes.h:591
std::optional< std::vector< bool > > delete_buffer_
typename ScalarEncoderType::DataType DstDataType
#define CHECK(condition)
Definition: Logger.h:291
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename ScalarEncoderType >
void data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::clearLocalState ( const size_t  num_elements)
inline

Definition at line 144 of file StringViewToArrayEncoder.h.

References data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_datums_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_sizes_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::is_null_, and data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::scalar_encoder_.

Referenced by data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::encodeAndAppendData().

144  {
145  scalar_encoder_.clear();
146  array_datums_.clear();
147  array_sizes_.clear();
148  is_null_.clear();
149  array_sizes_.reserve(num_elements);
150  array_datums_.reserve(num_elements);
151  is_null_.reserve(num_elements);
152  }

+ Here is the caller graph for this function:

template<typename ScalarEncoderType >
void data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::encodeAndAppendData ( const int8_t *  data,
const size_t  num_elements 
)
inlineoverridevirtual

Implements data_conversion::BaseConvertEncoder.

Definition at line 47 of file StringViewToArrayEncoder.h.

References data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::appendArrayDatums(), data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::clearLocalState(), data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::encodeScalarData(), data_conversion::BaseConvertEncoder::error_tracking_enabled_, and data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::scalar_encoder_.

47  {
48  auto typed_data = reinterpret_cast<const std::string_view*>(data);
49 
50  const import_export::CopyParams default_copy_params;
51 
52  std::optional<std::vector<bool>> error_occurred = std::nullopt;
53 
55  error_occurred = std::vector<bool>{};
56  error_occurred->reserve(num_elements);
57  }
58 
59  clearLocalState(num_elements);
60 
61  encodeScalarData(num_elements, typed_data, default_copy_params, error_occurred);
62 
63  auto current_data = reinterpret_cast<int8_t*>(
64  scalar_encoder_.getDstChunk().getBuffer()->getMemoryPtr());
65  size_t current_scalar_offset = 0;
66 
67  appendArrayDatums(num_elements, error_occurred, current_data, current_scalar_offset);
68  }
void encodeScalarData(const size_t num_elements, const std::string_view *typed_data, const import_export::CopyParams &default_copy_params, std::optional< std::vector< bool >> &error_occurred)
void appendArrayDatums(const size_t num_elements, std::optional< std::vector< bool >> &error_occurred, int8_t *current_data, size_t current_scalar_offset)
void clearLocalState(const size_t num_elements)

+ Here is the call graph for this function:

template<typename ScalarEncoderType >
void data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::encodeScalarData ( const size_t  num_elements,
const std::string_view *  typed_data,
const import_export::CopyParams default_copy_params,
std::optional< std::vector< bool >> &  error_occurred 
)
inline

Definition at line 154 of file StringViewToArrayEncoder.h.

References data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_sizes_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_views_, data_conversion::BaseConvertEncoder::error_tracking_enabled_, data_conversion::BaseConvertEncoder::has_nulls_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::is_null_, import_export::delimited_parser::parse_string_array(), and data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::scalar_encoder_.

Referenced by data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::encodeAndAppendData().

157  {
158  for (size_t i = 0; i < num_elements; ++i) {
160  error_occurred->push_back(false);
161  }
162  if (typed_data[i].empty()) {
163  is_null_.push_back(true);
164  array_sizes_.push_back(0);
166  continue;
167  }
168  is_null_.push_back(false);
169  array_.clear();
170  array_views_.clear();
171  try {
172  std::string s{typed_data[i]};
174  s, default_copy_params, array_, false);
175  array_sizes_.push_back(array_.size());
176  for (const auto& s : array_) {
177  array_views_.emplace_back(s.data(), s.length());
178  }
179  } catch (std::exception& except) {
181  error_occurred->back() = true;
182  array_sizes_.push_back(0);
183  continue;
184  } else {
185  throw except;
186  }
187  }
188  scalar_encoder_.encodeAndAppendData(reinterpret_cast<int8_t*>(array_views_.data()),
189  array_views_.size());
190  }
191 
192  scalar_encoder_.finalize(num_elements);
193  }
void parse_string_array(const std::string &s, const import_export::CopyParams &copy_params, std::vector< std::string > &string_vec, bool truncate_values)
Parses given string array and inserts into given vector of strings.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename ScalarEncoderType >
void data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::initialize ( )
inlineprivate

Definition at line 196 of file StringViewToArrayEncoder.h.

References data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::buffer_, ColumnDescriptor::columnType, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::dst_chunk_, data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::dst_type_info_, Chunk_NS::Chunk::getBuffer(), and Chunk_NS::Chunk::getColumnDesc().

Referenced by data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::StringViewToArrayEncoder().

196  {
197  auto type_info = dst_chunk_.getColumnDesc()->columnType;
198  dst_type_info_ = type_info;
200  }
const ColumnDescriptor * getColumnDesc() const
Definition: Chunk.h:65
AbstractBuffer * getBuffer() const
Definition: Chunk.h:146
SQLTypeInfo columnType

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<typename ScalarEncoderType >
std::vector<std::string> data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_
private
template<typename ScalarEncoderType >
std::vector<std::string_view> data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::array_views_
private
template<typename ScalarEncoderType >
const Chunk_NS::Chunk& data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::dst_chunk_
private
template<typename ScalarEncoderType >
const Chunk_NS::Chunk& data_conversion::StringViewToArrayEncoder< ScalarEncoderType >::scalar_temp_chunk_
private

Definition at line 204 of file StringViewToArrayEncoder.h.


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