OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
data_conversion::StringViewToScalarEncoder< DataType, MetadataType > Class Template Reference

#include <StringViewToScalarEncoder.h>

+ Inheritance diagram for data_conversion::StringViewToScalarEncoder< DataType, MetadataType >:
+ Collaboration diagram for data_conversion::StringViewToScalarEncoder< DataType, MetadataType >:

Public Member Functions

 StringViewToScalarEncoder (const Chunk_NS::Chunk &dst_chunk, const bool error_tracking_enabled)
 
void encodeAndAppendData (const int8_t *data, const size_t num_elements) override
 
void clear () override
 
const Chunk_NS::ChunkgetDstChunk () const
 
std::optional< std::vector
< bool > > & 
getDeleteBuffer ()
 
- Public Member Functions inherited from data_conversion::TypedBaseConvertEncoder< DataType, 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 ()
 
DataType convertAndUpdateMetadata (const std::string_view &typed_value)
 
DataType convert (const std::string_view &typed_value)
 

Private Attributes

SQLTypeInfo dst_type_info_
 
const Chunk_NS::Chunkdst_chunk_
 
AbstractBufferbuffer_
 
const bool is_date_in_days_
 
std::optional
< DateDaysOverflowValidator
date_days_overflow_validator_
 
std::optional
< DecimalOverflowValidator
decimal_overflow_validator_
 

Additional Inherited Members

- Public Types inherited from data_conversion::TypedBaseConvertEncoder< DataType, MetadataType >
using DataType = DataType
 
using MetadataType = MetadataType
 
- Protected Member Functions inherited from data_conversion::TypedBaseConvertEncoder< DataType, 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
template<typename DataType >
bool isNull (const DataType &typed_value)
 
- Protected Attributes inherited from data_conversion::TypedBaseConvertEncoder< DataType, 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 DataType, typename MetadataType = DataType>
class data_conversion::StringViewToScalarEncoder< DataType, MetadataType >

Definition at line 25 of file StringViewToScalarEncoder.h.

Constructor & Destructor Documentation

template<typename DataType , typename MetadataType = DataType>
data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::StringViewToScalarEncoder ( const Chunk_NS::Chunk dst_chunk,
const bool  error_tracking_enabled 
)
inline

Definition at line 27 of file StringViewToScalarEncoder.h.

References data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::initialize().

29  : TypedBaseConvertEncoder<DataType, MetadataType>(error_tracking_enabled)
30  , dst_chunk_(dst_chunk)
32  , date_days_overflow_validator_(std::nullopt)
33  , decimal_overflow_validator_(std::nullopt) {
34  initialize();
35  }
std::optional< DecimalOverflowValidator > decimal_overflow_validator_
const ColumnDescriptor * getColumnDesc() const
Definition: Chunk.h:65
bool is_date_in_days() const
Definition: sqltypes.h:1018
SQLTypeInfo columnType
std::optional< DateDaysOverflowValidator > date_days_overflow_validator_

+ Here is the call graph for this function:

Member Function Documentation

template<typename DataType , typename MetadataType = DataType>
void data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::clear ( )
inlineoverridevirtual

Reimplemented from data_conversion::BaseConvertEncoder.

Definition at line 45 of file StringViewToScalarEncoder.h.

References data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::buffer_, data_conversion::BaseConvertEncoder::clear(), and Data_Namespace::AbstractBuffer::resetToEmpty().

+ Here is the call graph for this function:

template<typename DataType , typename MetadataType = DataType>
DataType data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::convert ( const std::string_view &  typed_value)
inlineprivate

Definition at line 105 of file StringViewToScalarEncoder.h.

References CHECK, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::date_days_overflow_validator_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::decimal_overflow_validator_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::dst_type_info_, DateConverters::get_epoch_days_from_seconds(), data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::is_date_in_days_, SQLTypeInfo::is_none_encoded_string(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kENCODING_FIXED, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, run_benchmark_import::result, StringToDatum(), and UNREACHABLE.

Referenced by data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::convertAndUpdateMetadata().

105  {
106  if constexpr (std::is_same<DataType, std::string_view>::value) {
108  return typed_value;
109  }
110  } else {
112 
113  auto& type_info = dst_type_info_;
114 
115  // TODO: remove this CHECK if it shows up in profiling
116  CHECK(type_info.is_integer() || type_info.is_boolean() || type_info.is_fp() ||
117  type_info.is_decimal() || type_info.is_time_or_date());
118 
119  // TODO: the call to `StringToDatum` and the switch statement below can be
120  // merged into one switch calling the appropriate parsing subroutine and may
121  // improve performance. Profile if improvement is observed.
122  Datum d = StringToDatum(typed_value, const_cast<SQLTypeInfo&>(type_info));
123  DataType result{};
124  switch (type_info.get_type()) {
125  case kBOOLEAN:
126  result = d.boolval;
127  break;
128  case kBIGINT:
129  case kTIME:
130  case kTIMESTAMP:
131  result = d.bigintval;
132  break;
133  case kNUMERIC:
134  case kDECIMAL:
135  if (type_info.get_compression() == kENCODING_FIXED) {
136  decimal_overflow_validator_->validate(d.bigintval);
137  }
138  result = d.bigintval;
139  break;
140  case kDATE:
141  if (is_date_in_days_) {
142  date_days_overflow_validator_->validate(d.bigintval);
144  } else {
145  result = d.bigintval;
146  }
147  break;
148  case kINT:
149  result = d.intval;
150  break;
151  case kSMALLINT:
152  result = d.smallintval;
153  break;
154  case kTINYINT:
155  result = d.tinyintval;
156  break;
157  case kFLOAT:
158  result = d.floatval;
159  break;
160  case kDOUBLE:
161  result = d.doubleval;
162  break;
163  default:
164  UNREACHABLE();
165  }
166 
167  return result;
168  }
169  }
Definition: sqltypes.h:76
std::optional< DecimalOverflowValidator > decimal_overflow_validator_
#define UNREACHABLE()
Definition: Logger.h:338
Datum StringToDatum(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:339
Definition: sqltypes.h:80
bool is_none_encoded_string() const
Definition: sqltypes.h:647
#define CHECK(condition)
Definition: Logger.h:291
int64_t get_epoch_days_from_seconds(const int64_t seconds)
Definition: sqltypes.h:72
std::optional< DateDaysOverflowValidator > date_days_overflow_validator_
Definition: Datum.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename DataType , typename MetadataType = DataType>
DataType data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::convertAndUpdateMetadata ( const std::string_view &  typed_value)
inlineprivate

Definition at line 69 of file StringViewToScalarEncoder.h.

References data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::convert(), data_conversion::BaseConvertEncoder::delete_buffer_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::dst_type_info_, data_conversion::BaseConvertEncoder::error_tracking_enabled_, SQLTypeInfo::get_notnull(), data_conversion::TypedBaseConvertEncoder< DataType_, MetadataType_ >::getNull(), data_conversion::BaseConvertEncoder::has_nulls_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::is_date_in_days_, data_conversion::BaseConvertEncoder::isNull(), and data_conversion::TypedBaseConvertEncoder< DataType_, MetadataType_ >::updateMetadataStats().

Referenced by data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::encodeAndAppendData().

69  {
70  if (BaseConvertEncoder::isNull(typed_value)) {
73  throw std::runtime_error("NULL value not allowed in NOT NULL column");
74  }
76  } else {
78  BaseConvertEncoder::delete_buffer_->push_back(true);
79  } else {
80  BaseConvertEncoder::delete_buffer_->push_back(false);
81  }
82  }
84  }
85 
86  DataType converted_value{};
87  try {
88  converted_value = convert(typed_value);
90  converted_value, is_date_in_days_);
92  BaseConvertEncoder::delete_buffer_->push_back(false);
93  }
94  } catch (std::exception& except) {
97  BaseConvertEncoder::delete_buffer_->push_back(true);
98  } else {
99  throw;
100  }
101  }
102  return converted_value;
103  }
void updateMetadataStats(const DataType &typed_value, const bool is_date_in_days=false)
DataType convert(const std::string_view &typed_value)
bool isNull(const DataType &typed_value)
std::optional< std::vector< bool > > delete_buffer_
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 DataType , typename MetadataType = DataType>
void data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::encodeAndAppendData ( const int8_t *  data,
const size_t  num_elements 
)
inlineoverridevirtual

Implements data_conversion::BaseConvertEncoder.

Definition at line 37 of file StringViewToScalarEncoder.h.

References Data_Namespace::AbstractBuffer::append(), data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::buffer_, and data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::convertAndUpdateMetadata().

37  {
38  auto typed_data = reinterpret_cast<const std::string_view*>(data);
39  for (size_t i = 0; i < num_elements; ++i) {
40  auto converted_value = convertAndUpdateMetadata(typed_data[i]);
41  buffer_->append(reinterpret_cast<int8_t*>(&converted_value), sizeof(DataType));
42  }
43  }
DataType convertAndUpdateMetadata(const std::string_view &typed_value)
virtual void append(int8_t *src, const size_t num_bytes, const MemoryLevel src_buffer_type=CPU_LEVEL, const int device_id=-1)=0

+ Here is the call graph for this function:

template<typename DataType , typename MetadataType = DataType>
std::optional<std::vector<bool> >& data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::getDeleteBuffer ( )
inline

Definition at line 52 of file StringViewToScalarEncoder.h.

References data_conversion::BaseConvertEncoder::delete_buffer_.

52  {
54  }
std::optional< std::vector< bool > > delete_buffer_
template<typename DataType , typename MetadataType = DataType>
const Chunk_NS::Chunk& data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::getDstChunk ( ) const
inline
template<typename DataType , typename MetadataType = DataType>
void data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::initialize ( )
inlineprivate

Definition at line 57 of file StringViewToScalarEncoder.h.

References data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::buffer_, ColumnDescriptor::columnType, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::date_days_overflow_validator_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::decimal_overflow_validator_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::dst_chunk_, data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::dst_type_info_, Chunk_NS::Chunk::getBuffer(), Chunk_NS::Chunk::getColumnDesc(), data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::is_date_in_days_, and SQLTypeInfo::is_decimal().

Referenced by data_conversion::StringViewToScalarEncoder< DataType, MetadataType >::StringViewToScalarEncoder().

57  {
58  auto type_info = dst_chunk_.getColumnDesc()->columnType;
59  dst_type_info_ = type_info;
61  if (is_date_in_days_) {
63  }
64  if (dst_type_info_.is_decimal()) {
66  }
67  }
std::optional< DecimalOverflowValidator > decimal_overflow_validator_
const ColumnDescriptor * getColumnDesc() const
Definition: Chunk.h:65
AbstractBuffer * getBuffer() const
Definition: Chunk.h:146
SQLTypeInfo columnType
std::optional< DateDaysOverflowValidator > date_days_overflow_validator_
bool is_decimal() const
Definition: sqltypes.h:570

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation


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