OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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)
 
ChunkMetadata appendData (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 (ChunkMetadata &chunkMetadata) override
 
ChunkMetadata getMetadata (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 dst, const size_t numElements) 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
 

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 32 of file NoneEncoder.h.

Constructor & Destructor Documentation

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

Definition at line 34 of file NoneEncoder.h.

35  : Encoder(buffer)
36  , dataMin(std::numeric_limits<T>::max())
37  , dataMax(std::numeric_limits<T>::lowest())
38  , has_nulls(false) {}
Encoder(Data_Namespace::AbstractBuffer *buffer)
Definition: Encoder.cpp:221
bool has_nulls
Definition: NoneEncoder.h:183

Member Function Documentation

template<typename T>
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 40 of file NoneEncoder.h.

References Data_Namespace::AbstractBuffer::append(), Encoder::buffer_, CHECK(), CHECK_GE, NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, Encoder::decimal_overflow_validator_, NoneEncoder< T >::getMetadata(), NoneEncoder< T >::has_nulls, Encoder::num_elems_, DecimalOverflowValidator::validate(), and Data_Namespace::AbstractBuffer::write().

44  {
45  T* unencodedData = reinterpret_cast<T*>(src_data);
46  std::vector<T> encoded_data;
47  if (replicating) {
48  encoded_data.resize(num_elems_to_append);
49  }
50  for (size_t i = 0; i < num_elems_to_append; ++i) {
51  size_t ri = replicating ? 0 : i;
52  T data = unencodedData[ri];
53  if (replicating) {
54  encoded_data[i] = data;
55  }
56  if (data == none_encoded_null_value<T>()) {
57  has_nulls = true;
58  } else {
60  dataMin = std::min(dataMin, data);
61  dataMax = std::max(dataMax, data);
62  }
63  }
64  if (offset == -1) {
65  num_elems_ += num_elems_to_append;
66  buffer_->append(
67  replicating ? reinterpret_cast<int8_t*>(encoded_data.data()) : src_data,
68  num_elems_to_append * sizeof(T));
69  if (!replicating) {
70  src_data += num_elems_to_append * sizeof(T);
71  }
72  } else {
73  num_elems_ = offset + num_elems_to_append;
74  CHECK(!replicating);
75  CHECK_GE(offset, 0);
76  buffer_->write(
77  src_data, num_elems_to_append * sizeof(T), static_cast<size_t>(offset));
78  }
79  ChunkMetadata chunkMetadata;
80  getMetadata(chunkMetadata);
81 
82  return chunkMetadata;
83  }
size_t num_elems_
Definition: Encoder.h:191
DecimalOverflowValidator decimal_overflow_validator_
Definition: Encoder.h:196
#define CHECK_GE(x, y)
Definition: Logger.h:210
CHECK(cgen_state)
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:193
void getMetadata(ChunkMetadata &chunkMetadata) override
Definition: NoneEncoder.h:85
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
void validate(T value)
Definition: Encoder.h:54
bool has_nulls
Definition: NoneEncoder.h:183
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 T>
void NoneEncoder< T >::copyMetadata ( const Encoder copyFromEncoder)
inlineoverridevirtual

Implements Encoder.

Definition at line 173 of file NoneEncoder.h.

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

173  {
174  num_elems_ = copyFromEncoder->getNumElems();
175  auto castedEncoder = reinterpret_cast<const NoneEncoder<T>*>(copyFromEncoder);
176  dataMin = castedEncoder->dataMin;
177  dataMax = castedEncoder->dataMax;
178  has_nulls = castedEncoder->has_nulls;
179  }
size_t num_elems_
Definition: Encoder.h:191
size_t getNumElems() const
Definition: Encoder.h:187
bool has_nulls
Definition: NoneEncoder.h:183

+ Here is the call graph for this function:

template<typename T>
void NoneEncoder< T >::getMetadata ( ChunkMetadata chunkMetadata)
inlineoverridevirtual

Reimplemented from Encoder.

Definition at line 85 of file NoneEncoder.h.

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

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

85  {
86  Encoder::getMetadata(chunkMetadata); // call on parent class
87  chunkMetadata.fillChunkStats(dataMin, dataMax, has_nulls);
88  }
void fillChunkStats(const T min, const T max, const bool has_nulls)
Definition: ChunkMetadata.h:38
virtual void getMetadata(ChunkMetadata &chunkMetadata)
Definition: Encoder.cpp:227
bool has_nulls
Definition: NoneEncoder.h:183

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Implements Encoder.

Definition at line 91 of file NoneEncoder.h.

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

91  {
92  ChunkMetadata chunk_metadata{ti, 0, 0, ChunkStats{}};
93  chunk_metadata.fillChunkStats(dataMin, dataMax, has_nulls);
94  return chunk_metadata;
95  }
bool has_nulls
Definition: NoneEncoder.h:183
template<typename T>
void NoneEncoder< T >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 151 of file NoneEncoder.h.

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

151  {
152  // assumes pointer is already in right place
153  fread((int8_t*)&num_elems_, sizeof(size_t), 1, f);
154  fread((int8_t*)&dataMin, sizeof(T), 1, f);
155  fread((int8_t*)&dataMax, sizeof(T), 1, f);
156  fread((int8_t*)&has_nulls, sizeof(bool), 1, f);
157  }
size_t num_elems_
Definition: Encoder.h:191
bool has_nulls
Definition: NoneEncoder.h:183
template<typename T>
void NoneEncoder< T >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 134 of file NoneEncoder.h.

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

134  {
135  const auto that_typed = static_cast<const NoneEncoder&>(that);
136  if (that_typed.has_nulls) {
137  has_nulls = true;
138  }
139  dataMin = std::min(dataMin, that_typed.dataMin);
140  dataMax = std::max(dataMax, that_typed.dataMax);
141  }
bool has_nulls
Definition: NoneEncoder.h:183
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 159 of file NoneEncoder.h.

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

159  {
160  const auto new_min = DatumFetcher::getDatumVal<T>(stats.min);
161  const auto new_max = DatumFetcher::getDatumVal<T>(stats.max);
162 
163  if (dataMin == new_min && dataMax == new_max && has_nulls == stats.has_nulls) {
164  return false;
165  }
166 
167  dataMin = new_min;
168  dataMax = new_max;
169  has_nulls = stats.has_nulls;
170  return true;
171  }
bool has_nulls
Definition: NoneEncoder.h:183
template<typename T>
void NoneEncoder< T >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 98 of file NoneEncoder.h.

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

98  {
99  if (is_null) {
100  has_nulls = true;
101  } else {
102  const auto data = static_cast<T>(val);
103  dataMin = std::min(dataMin, data);
104  dataMax = std::max(dataMax, data);
105  }
106  }
bool is_null(const T &v, const SQLTypeInfo &t)
bool has_nulls
Definition: NoneEncoder.h:183
template<typename T>
void NoneEncoder< T >::updateStats ( const double  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 109 of file NoneEncoder.h.

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

109  {
110  if (is_null) {
111  has_nulls = true;
112  } else {
113  const auto data = static_cast<T>(val);
114  dataMin = std::min(dataMin, data);
115  dataMax = std::max(dataMax, data);
116  }
117  }
bool is_null(const T &v, const SQLTypeInfo &t)
bool has_nulls
Definition: NoneEncoder.h:183
template<typename T>
void NoneEncoder< T >::updateStats ( const int8_t *const  dst,
const size_t  numElements 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 119 of file NoneEncoder.h.

References NoneEncoder< T >::dataMax, NoneEncoder< T >::dataMin, Encoder::decimal_overflow_validator_, NoneEncoder< T >::has_nulls, and DecimalOverflowValidator::validate().

119  {
120  const T* unencodedData = reinterpret_cast<const T*>(dst);
121  for (size_t i = 0; i < numElements; ++i) {
122  T data = unencodedData[i];
123  if (data != none_encoded_null_value<T>()) {
125  dataMin = std::min(dataMin, data);
126  dataMax = std::max(dataMax, data);
127  } else {
128  has_nulls = true;
129  }
130  }
131  }
DecimalOverflowValidator decimal_overflow_validator_
Definition: Encoder.h:196
void validate(T value)
Definition: Encoder.h:54
bool has_nulls
Definition: NoneEncoder.h:183

+ Here is the call graph for this function:

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

Implements Encoder.

Definition at line 143 of file NoneEncoder.h.

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

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

Member Data Documentation


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