OmniSciDB  1dac507f6e
 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 *&srcData, const size_t numAppendElems, const SQLTypeInfo &, const bool replicating=false) 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 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:159

Member Function Documentation

template<typename T>
ChunkMetadata NoneEncoder< T >::appendData ( int8_t *&  srcData,
const size_t  numAppendElems,
const SQLTypeInfo ,
const bool  replicating = false 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 40 of file NoneEncoder.h.

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

43  {
44  T* unencodedData = reinterpret_cast<T*>(srcData);
45  std::vector<T> encoded_data;
46  if (replicating) {
47  encoded_data.resize(numAppendElems);
48  }
49  for (size_t i = 0; i < numAppendElems; ++i) {
50  size_t ri = replicating ? 0 : i;
51  T data = unencodedData[ri];
52  if (replicating) {
53  encoded_data[i] = data;
54  }
55  if (data == none_encoded_null_value<T>()) {
56  has_nulls = true;
57  } else {
59  dataMin = std::min(dataMin, data);
60  dataMax = std::max(dataMax, data);
61  }
62  }
63  num_elems_ += numAppendElems;
64  buffer_->append(
65  replicating ? reinterpret_cast<int8_t*>(encoded_data.data()) : srcData,
66  numAppendElems * sizeof(T));
67  ChunkMetadata chunkMetadata;
68  getMetadata(chunkMetadata);
69  if (!replicating) {
70  srcData += numAppendElems * sizeof(T);
71  }
72  return chunkMetadata;
73  }
size_t num_elems_
Definition: Encoder.h:179
DecimalOverflowValidator decimal_overflow_validator_
Definition: Encoder.h:184
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:181
void getMetadata(ChunkMetadata &chunkMetadata) override
Definition: NoneEncoder.h:75
void validate(T value)
Definition: Encoder.h:54
bool has_nulls
Definition: NoneEncoder.h:159
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 149 of file NoneEncoder.h.

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

149  {
150  num_elems_ = copyFromEncoder->getNumElems();
151  auto castedEncoder = reinterpret_cast<const NoneEncoder<T>*>(copyFromEncoder);
152  dataMin = castedEncoder->dataMin;
153  dataMax = castedEncoder->dataMax;
154  has_nulls = castedEncoder->has_nulls;
155  }
size_t num_elems_
Definition: Encoder.h:179
size_t getNumElems() const
Definition: Encoder.h:175
bool has_nulls
Definition: NoneEncoder.h:159

+ Here is the call graph for this function:

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

Reimplemented from Encoder.

Definition at line 75 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().

75  {
76  Encoder::getMetadata(chunkMetadata); // call on parent class
77  chunkMetadata.fillChunkStats(dataMin, dataMax, has_nulls);
78  }
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:159

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

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

81  {
82  ChunkMetadata chunk_metadata{ti, 0, 0, ChunkStats{}};
83  chunk_metadata.fillChunkStats(dataMin, dataMax, has_nulls);
84  return chunk_metadata;
85  }
bool has_nulls
Definition: NoneEncoder.h:159
template<typename T>
void NoneEncoder< T >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 127 of file NoneEncoder.h.

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

127  {
128  // assumes pointer is already in right place
129  fread((int8_t*)&num_elems_, sizeof(size_t), 1, f);
130  fread((int8_t*)&dataMin, sizeof(T), 1, f);
131  fread((int8_t*)&dataMax, sizeof(T), 1, f);
132  fread((int8_t*)&has_nulls, sizeof(bool), 1, f);
133  }
size_t num_elems_
Definition: Encoder.h:179
bool has_nulls
Definition: NoneEncoder.h:159
template<typename T>
void NoneEncoder< T >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 110 of file NoneEncoder.h.

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

110  {
111  const auto that_typed = static_cast<const NoneEncoder&>(that);
112  if (that_typed.has_nulls) {
113  has_nulls = true;
114  }
115  dataMin = std::min(dataMin, that_typed.dataMin);
116  dataMax = std::max(dataMax, that_typed.dataMax);
117  }
bool has_nulls
Definition: NoneEncoder.h:159
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 135 of file NoneEncoder.h.

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

135  {
136  const auto new_min = DatumFetcher::getDatumVal<T>(stats.min);
137  const auto new_max = DatumFetcher::getDatumVal<T>(stats.max);
138 
139  if (dataMin == new_min && dataMax == new_max && has_nulls == stats.has_nulls) {
140  return false;
141  }
142 
143  dataMin = new_min;
144  dataMax = new_max;
145  has_nulls = stats.has_nulls;
146  return true;
147  }
bool has_nulls
Definition: NoneEncoder.h:159
template<typename T>
void NoneEncoder< T >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 88 of file NoneEncoder.h.

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

88  {
89  if (is_null) {
90  has_nulls = true;
91  } else {
92  const auto data = static_cast<T>(val);
93  dataMin = std::min(dataMin, data);
94  dataMax = std::max(dataMax, data);
95  }
96  }
bool is_null(const T &v, const SQLTypeInfo &t)
bool has_nulls
Definition: NoneEncoder.h:159
template<typename T>
void NoneEncoder< T >::updateStats ( const double  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 99 of file NoneEncoder.h.

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

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

Implements Encoder.

Definition at line 119 of file NoneEncoder.h.

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

119  {
120  // assumes pointer is already in right place
121  fwrite((int8_t*)&num_elems_, sizeof(size_t), 1, f);
122  fwrite((int8_t*)&dataMin, sizeof(T), 1, f);
123  fwrite((int8_t*)&dataMax, sizeof(T), 1, f);
124  fwrite((int8_t*)&has_nulls, sizeof(bool), 1, f);
125  }
size_t num_elems_
Definition: Encoder.h:179
bool has_nulls
Definition: NoneEncoder.h:159

Member Data Documentation


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