OmniSciDB  f632821e96
NoneEncoder< T > Class Template Reference

#include <NoneEncoder.h>

+ Inheritance diagram for NoneEncoder< T >:
+ Collaboration diagram for NoneEncoder< T >:

Public Member Functions

 NoneEncoder (Data_Namespace::AbstractBuffer *buffer)
 
std::shared_ptr< ChunkMetadataappendData (int8_t *&src_data, const size_t num_elems_to_append, const SQLTypeInfo &, const bool replicating=false, const int64_t offset=-1) override
 
void getMetadata (const std::shared_ptr< ChunkMetadata > &chunkMetadata) override
 
std::shared_ptr< ChunkMetadatagetMetadata (const SQLTypeInfo &ti) override
 
void updateStats (const int64_t val, const bool is_null) override
 
void updateStats (const double val, const bool is_null) override
 
void updateStats (const int8_t *const src_data, const size_t num_elements) override
 
void updateStats (const std::vector< std::string > *const src_data, const size_t start_idx, const size_t num_elements) override
 
void updateStats (const std::vector< ArrayDatum > *const src_data, const size_t start_idx, const size_t num_elements) override
 
void reduceStats (const Encoder &that) override
 
void writeMetadata (FILE *f) override
 
void readMetadata (FILE *f) override
 
bool resetChunkStats (const ChunkStats &stats) override
 : Reset chunk level stats (min, max, nulls) using new values from the argument. More...
 
void copyMetadata (const Encoder *copyFromEncoder) override
 
- Public Member Functions inherited from Encoder
 Encoder (Data_Namespace::AbstractBuffer *buffer)
 
virtual ~Encoder ()
 
size_t getNumElems () const
 
void setNumElems (const size_t num_elems)
 

Public Attributes

dataMin
 
dataMax
 
bool has_nulls
 

Private Member Functions

validateDataAndUpdateStats (const T &unencoded_data)
 

Additional Inherited Members

- Static Public Member Functions inherited from Encoder
static EncoderCreate (Data_Namespace::AbstractBuffer *buffer, const SQLTypeInfo sqlType)
 
- Protected Attributes inherited from Encoder
size_t num_elems_
 
Data_Namespace::AbstractBufferbuffer_
 
DecimalOverflowValidator decimal_overflow_validator_
 
DateDaysOverflowValidator date_days_overflow_validator_
 

Detailed Description

template<typename T>
class NoneEncoder< T >

Definition at line 36 of file NoneEncoder.h.

Constructor & Destructor Documentation

◆ NoneEncoder()

template<typename T>
NoneEncoder< T >::NoneEncoder ( Data_Namespace::AbstractBuffer buffer)
inline

Definition at line 38 of file NoneEncoder.h.

39  : Encoder(buffer)
40  , dataMin(std::numeric_limits<T>::max())
41  , dataMax(std::numeric_limits<T>::lowest())
42  , has_nulls(false) {}
Encoder(Data_Namespace::AbstractBuffer *buffer)
Definition: Encoder.cpp:221
bool has_nulls
Definition: NoneEncoder.h:184

Member Function Documentation

◆ appendData()

template<typename T>
std::shared_ptr<ChunkMetadata> NoneEncoder< T >::appendData ( int8_t *&  src_data,
const size_t  num_elems_to_append,
const SQLTypeInfo ti,
const bool  replicating = false,
const int64_t  offset = -1 
)
inlineoverridevirtual

Append data to the chunk buffer backing this encoder.

Parameters
src_dataSource data for the append
num_elems_to_appendNumber of elements to append
tiSQL Type Info for the column TODO(adb): used?
replicatingPass one value and fill the chunk with it
offsetWrite data starting at a given offset. Default is -1 which indicates an append, an offset of 0 rewrites the chunk up to num_elems_to_append.

Implements Encoder.

Definition at line 44 of file NoneEncoder.h.

References Data_Namespace::AbstractBuffer::append(), Encoder::buffer_, CHECK, CHECK_GE, NoneEncoder< T >::getMetadata(), Encoder::num_elems_, NoneEncoder< T >::validateDataAndUpdateStats(), and Data_Namespace::AbstractBuffer::write().

48  {
49  T* unencodedData = reinterpret_cast<T*>(src_data);
50  std::vector<T> encoded_data;
51  if (replicating) {
52  encoded_data.resize(num_elems_to_append);
53  }
54  for (size_t i = 0; i < num_elems_to_append; ++i) {
55  size_t ri = replicating ? 0 : i;
56  T data = validateDataAndUpdateStats(unencodedData[ri]);
57  if (replicating) {
58  encoded_data[i] = data;
59  }
60  }
61  if (offset == -1) {
62  num_elems_ += num_elems_to_append;
63  buffer_->append(
64  replicating ? reinterpret_cast<int8_t*>(encoded_data.data()) : src_data,
65  num_elems_to_append * sizeof(T));
66  if (!replicating) {
67  src_data += num_elems_to_append * sizeof(T);
68  }
69  } else {
70  num_elems_ = offset + num_elems_to_append;
71  CHECK(!replicating);
72  CHECK_GE(offset, 0);
73  buffer_->write(
74  src_data, num_elems_to_append * sizeof(T), static_cast<size_t>(offset));
75  }
76  auto chunk_metadata = std::make_shared<ChunkMetadata>();
77  getMetadata(chunk_metadata);
78  return chunk_metadata;
79  }
size_t num_elems_
Definition: Encoder.h:218
#define CHECK_GE(x, y)
Definition: Logger.h:210
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:220
void getMetadata(const std::shared_ptr< ChunkMetadata > &chunkMetadata) override
Definition: NoneEncoder.h:81
virtual void write(int8_t *src, const size_t num_bytes, const size_t offset=0, const MemoryLevel src_buffer_type=CPU_LEVEL, const int src_device_id=-1)=0
virtual void append(int8_t *src, const size_t num_bytes, const MemoryLevel src_buffer_type=CPU_LEVEL, const int device_id=-1)=0
#define CHECK(condition)
Definition: Logger.h:197
T validateDataAndUpdateStats(const T &unencoded_data)
Definition: NoneEncoder.h:187
+ Here is the call graph for this function:

◆ copyMetadata()

template<typename T>
void NoneEncoder< T >::copyMetadata ( const Encoder copyFromEncoder)
inlineoverridevirtual

Implements Encoder.

Definition at line 174 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, Encoder::getNumElems(), NoneEncoder< T >::has_nulls, and Encoder::num_elems_.

174  {
175  num_elems_ = copyFromEncoder->getNumElems();
176  auto castedEncoder = reinterpret_cast<const NoneEncoder<T>*>(copyFromEncoder);
177  dataMin = castedEncoder->dataMin;
178  dataMax = castedEncoder->dataMax;
179  has_nulls = castedEncoder->has_nulls;
180  }
size_t num_elems_
Definition: Encoder.h:218
bool has_nulls
Definition: NoneEncoder.h:184
size_t getNumElems() const
Definition: Encoder.h:214
+ Here is the call graph for this function:

◆ getMetadata() [1/2]

template<typename T>
void NoneEncoder< T >::getMetadata ( const std::shared_ptr< ChunkMetadata > &  chunkMetadata)
inlineoverridevirtual

Reimplemented from Encoder.

Definition at line 81 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, Encoder::getMetadata(), and NoneEncoder< T >::has_nulls.

Referenced by NoneEncoder< T >::appendData().

81  {
82  Encoder::getMetadata(chunkMetadata); // call on parent class
83  chunkMetadata->fillChunkStats(dataMin, dataMax, has_nulls);
84  }
virtual void getMetadata(const std::shared_ptr< ChunkMetadata > &chunkMetadata)
Definition: Encoder.cpp:227
bool has_nulls
Definition: NoneEncoder.h:184
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMetadata() [2/2]

template<typename T>
std::shared_ptr<ChunkMetadata> NoneEncoder< T >::getMetadata ( const SQLTypeInfo ti)
inlineoverridevirtual

Implements Encoder.

Definition at line 87 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, and NoneEncoder< T >::has_nulls.

87  {
88  auto chunk_metadata = std::make_shared<ChunkMetadata>(ti, 0, 0, ChunkStats{});
89  chunk_metadata->fillChunkStats(dataMin, dataMax, has_nulls);
90  return chunk_metadata;
91  }
bool has_nulls
Definition: NoneEncoder.h:184

◆ readMetadata()

template<typename T>
void NoneEncoder< T >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 152 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, NoneEncoder< T >::has_nulls, and Encoder::num_elems_.

152  {
153  // assumes pointer is already in right place
154  fread((int8_t*)&num_elems_, sizeof(size_t), 1, f);
155  fread((int8_t*)&dataMin, sizeof(T), 1, f);
156  fread((int8_t*)&dataMax, sizeof(T), 1, f);
157  fread((int8_t*)&has_nulls, sizeof(bool), 1, f);
158  }
size_t num_elems_
Definition: Encoder.h:218
bool has_nulls
Definition: NoneEncoder.h:184

◆ reduceStats()

template<typename T>
void NoneEncoder< T >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 135 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, and NoneEncoder< T >::has_nulls.

135  {
136  const auto that_typed = static_cast<const NoneEncoder&>(that);
137  if (that_typed.has_nulls) {
138  has_nulls = true;
139  }
140  dataMin = std::min(dataMin, that_typed.dataMin);
141  dataMax = std::max(dataMax, that_typed.dataMax);
142  }
bool has_nulls
Definition: NoneEncoder.h:184

◆ resetChunkStats()

template<typename T>
bool NoneEncoder< T >::resetChunkStats ( const ChunkStats )
inlineoverridevirtual

: Reset chunk level stats (min, max, nulls) using new values from the argument.

Returns
: True if an update occurred and the chunk needs to be flushed. False otherwise. Default false if metadata update is unsupported. Only reset chunk stats if the incoming stats differ from the current stats.

Reimplemented from Encoder.

Definition at line 160 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, ChunkStats::has_nulls, NoneEncoder< T >::has_nulls, ChunkStats::max, and ChunkStats::min.

160  {
161  const auto new_min = DatumFetcher::getDatumVal<T>(stats.min);
162  const auto new_max = DatumFetcher::getDatumVal<T>(stats.max);
163 
164  if (dataMin == new_min && dataMax == new_max && has_nulls == stats.has_nulls) {
165  return false;
166  }
167 
168  dataMin = new_min;
169  dataMax = new_max;
170  has_nulls = stats.has_nulls;
171  return true;
172  }
bool has_nulls
Definition: NoneEncoder.h:184

◆ updateStats() [1/5]

template<typename T>
void NoneEncoder< T >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 94 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, and NoneEncoder< T >::has_nulls.

94  {
95  if (is_null) {
96  has_nulls = true;
97  } else {
98  const auto data = static_cast<T>(val);
99  dataMin = std::min(dataMin, data);
100  dataMax = std::max(dataMax, data);
101  }
102  }
bool is_null(const T &v, const SQLTypeInfo &t)
bool has_nulls
Definition: NoneEncoder.h:184

◆ updateStats() [2/5]

template<typename T>
void NoneEncoder< T >::updateStats ( const double  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 105 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, and NoneEncoder< T >::has_nulls.

105  {
106  if (is_null) {
107  has_nulls = true;
108  } else {
109  const auto data = static_cast<T>(val);
110  dataMin = std::min(dataMin, data);
111  dataMax = std::max(dataMax, data);
112  }
113  }
bool is_null(const T &v, const SQLTypeInfo &t)
bool has_nulls
Definition: NoneEncoder.h:184

◆ updateStats() [3/5]

template<typename T>
void NoneEncoder< T >::updateStats ( const int8_t *const  src_data,
const size_t  num_elements 
)
inlineoverridevirtual

Update statistics for data without appending.

Parameters
src_data- the data with which to update statistics
num_elements- the number of elements to scan in the data

Implements Encoder.

Definition at line 115 of file NoneEncoder.h.

References NoneEncoder< T >::validateDataAndUpdateStats().

115  {
116  const T* unencoded_data = reinterpret_cast<const T*>(src_data);
117  for (size_t i = 0; i < num_elements; ++i) {
118  validateDataAndUpdateStats(unencoded_data[i]);
119  }
120  }
T validateDataAndUpdateStats(const T &unencoded_data)
Definition: NoneEncoder.h:187
+ Here is the call graph for this function:

◆ updateStats() [4/5]

template<typename T>
void NoneEncoder< T >::updateStats ( const std::vector< std::string > *const  src_data,
const size_t  start_idx,
const size_t  num_elements 
)
inlineoverridevirtual

Update statistics for string data without appending.

Parameters
src_data- the string data with which to update statistics
start_idx- the offset into src_data to start the update
num_elements- the number of elements to scan in the string data

Implements Encoder.

Definition at line 122 of file NoneEncoder.h.

References UNREACHABLE.

124  {
125  UNREACHABLE();
126  }
#define UNREACHABLE()
Definition: Logger.h:241

◆ updateStats() [5/5]

template<typename T>
void NoneEncoder< T >::updateStats ( const std::vector< ArrayDatum > *const  src_data,
const size_t  start_idx,
const size_t  num_elements 
)
inlineoverridevirtual

Update statistics for array data without appending.

Parameters
src_data- the array data with which to update statistics
start_idx- the offset into src_data to start the update
num_elements- the number of elements to scan in the array data

Implements Encoder.

Definition at line 128 of file NoneEncoder.h.

References UNREACHABLE.

130  {
131  UNREACHABLE();
132  }
#define UNREACHABLE()
Definition: Logger.h:241

◆ validateDataAndUpdateStats()

template<typename T>
T NoneEncoder< T >::validateDataAndUpdateStats ( const T &  unencoded_data)
inlineprivate

Definition at line 187 of file NoneEncoder.h.

References Encoder::decimal_overflow_validator_, and DecimalOverflowValidator::validate().

Referenced by NoneEncoder< T >::appendData(), and NoneEncoder< T >::updateStats().

187  {
188  if (unencoded_data == none_encoded_null_value<T>()) {
189  has_nulls = true;
190  } else {
191  decimal_overflow_validator_.validate(unencoded_data);
192  dataMin = std::min(dataMin, unencoded_data);
193  dataMax = std::max(dataMax, unencoded_data);
194  }
195  return unencoded_data;
196  }
DecimalOverflowValidator decimal_overflow_validator_
Definition: Encoder.h:222
void validate(T value)
Definition: Encoder.h:54
bool has_nulls
Definition: NoneEncoder.h:184
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writeMetadata()

template<typename T>
void NoneEncoder< T >::writeMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 144 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, NoneEncoder< T >::has_nulls, and Encoder::num_elems_.

144  {
145  // assumes pointer is already in right place
146  fwrite((int8_t*)&num_elems_, sizeof(size_t), 1, f);
147  fwrite((int8_t*)&dataMin, sizeof(T), 1, f);
148  fwrite((int8_t*)&dataMax, sizeof(T), 1, f);
149  fwrite((int8_t*)&has_nulls, sizeof(bool), 1, f);
150  }
size_t num_elems_
Definition: Encoder.h:218
bool has_nulls
Definition: NoneEncoder.h:184

Member Data Documentation

◆ dataMax

◆ dataMin

◆ has_nulls


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