OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FixedLengthEncoder< T, V > Class Template Reference

#include <FixedLengthEncoder.h>

+ Inheritance diagram for FixedLengthEncoder< T, V >:
+ Collaboration diagram for FixedLengthEncoder< T, V >:

Public Member Functions

 FixedLengthEncoder (Data_Namespace::AbstractBuffer *buffer)
 
ChunkMetadata appendData (int8_t *&src_data, const size_t num_elems_to_append, const SQLTypeInfo &ti, 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 numBytes) override
 
void reduceStats (const Encoder &that) override
 
void copyMetadata (const Encoder *copyFromEncoder) 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...
 
- 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, typename V>
class FixedLengthEncoder< T, V >

Definition at line 30 of file FixedLengthEncoder.h.

Constructor & Destructor Documentation

template<typename T, typename V>
FixedLengthEncoder< T, V >::FixedLengthEncoder ( Data_Namespace::AbstractBuffer buffer)
inline

Definition at line 32 of file FixedLengthEncoder.h.

33  : Encoder(buffer)
34  , dataMin(std::numeric_limits<T>::max())
35  , dataMax(std::numeric_limits<T>::min())
36  , has_nulls(false) {}
Encoder(Data_Namespace::AbstractBuffer *buffer)
Definition: Encoder.cpp:221

Member Function Documentation

template<typename T, typename V>
ChunkMetadata FixedLengthEncoder< T, V >::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 38 of file FixedLengthEncoder.h.

References Data_Namespace::AbstractBuffer::append(), Encoder::buffer_, CHECK(), CHECK_GE, FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, Encoder::decimal_overflow_validator_, logger::ERROR, FixedLengthEncoder< T, V >::getMetadata(), FixedLengthEncoder< T, V >::has_nulls, LOG, Encoder::num_elems_, to_string(), DecimalOverflowValidator::validate(), and Data_Namespace::AbstractBuffer::write().

42  {
43  T* unencoded_data = reinterpret_cast<T*>(src_data);
44  auto encoded_data = std::make_unique<V[]>(num_elems_to_append);
45  for (size_t i = 0; i < num_elems_to_append; ++i) {
46  size_t ri = replicating ? 0 : i;
47  encoded_data.get()[i] = static_cast<V>(unencoded_data[ri]);
48  if (unencoded_data[ri] != encoded_data.get()[i]) {
49  decimal_overflow_validator_.validate(unencoded_data[ri]);
50  LOG(ERROR) << "Fixed encoding failed, Unencoded: " +
51  std::to_string(unencoded_data[ri]) +
52  " encoded: " + std::to_string(encoded_data.get()[i]);
53  } else {
54  T data = unencoded_data[ri];
55  if (data == std::numeric_limits<V>::min()) {
56  has_nulls = true;
57  } else {
59  dataMin = std::min(dataMin, data);
60  dataMax = std::max(dataMax, data);
61  }
62  }
63  }
64 
65  // assume always CPU_BUFFER?
66  if (offset == -1) {
67  num_elems_ += num_elems_to_append;
68  buffer_->append(reinterpret_cast<int8_t*>(encoded_data.get()),
69  num_elems_to_append * sizeof(V));
70  if (!replicating) {
71  src_data += num_elems_to_append * sizeof(T);
72  }
73  } else {
74  num_elems_ = offset + num_elems_to_append;
75  CHECK(!replicating);
76  CHECK_GE(offset, 0);
77  buffer_->write(reinterpret_cast<int8_t*>(encoded_data.get()),
78  num_elems_to_append * sizeof(V),
79  static_cast<size_t>(offset));
80  }
81  ChunkMetadata chunkMetadata;
82  getMetadata(chunkMetadata);
83  return chunkMetadata;
84  }
size_t num_elems_
Definition: Encoder.h:191
DecimalOverflowValidator decimal_overflow_validator_
Definition: Encoder.h:196
#define LOG(tag)
Definition: Logger.h:188
#define CHECK_GE(x, y)
Definition: Logger.h:210
std::string to_string(char const *&&v)
CHECK(cgen_state)
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:193
void getMetadata(ChunkMetadata &chunkMetadata) override
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
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, typename V>
void FixedLengthEncoder< T, V >::copyMetadata ( const Encoder copyFromEncoder)
inlineoverridevirtual

Implements Encoder.

Definition at line 134 of file FixedLengthEncoder.h.

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

134  {
135  num_elems_ = copyFromEncoder->getNumElems();
136  auto castedEncoder =
137  reinterpret_cast<const FixedLengthEncoder<T, V>*>(copyFromEncoder);
138  dataMin = castedEncoder->dataMin;
139  dataMax = castedEncoder->dataMax;
140  has_nulls = castedEncoder->has_nulls;
141  }
size_t num_elems_
Definition: Encoder.h:191
size_t getNumElems() const
Definition: Encoder.h:187

+ Here is the call graph for this function:

template<typename T, typename V>
void FixedLengthEncoder< T, V >::getMetadata ( ChunkMetadata chunkMetadata)
inlineoverridevirtual

Reimplemented from Encoder.

Definition at line 86 of file FixedLengthEncoder.h.

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

Referenced by FixedLengthEncoder< T, V >::appendData().

86  {
87  Encoder::getMetadata(chunkMetadata); // call on parent class
88  chunkMetadata.fillChunkStats(dataMin, dataMax, has_nulls);
89  }
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T, typename V>
ChunkMetadata FixedLengthEncoder< T, V >::getMetadata ( const SQLTypeInfo ti)
inlineoverridevirtual

Implements Encoder.

Definition at line 92 of file FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, and FixedLengthEncoder< T, V >::has_nulls.

92  {
93  ChunkMetadata chunk_metadata{ti, 0, 0, ChunkStats{}};
94  chunk_metadata.fillChunkStats(dataMin, dataMax, has_nulls);
95  return chunk_metadata;
96  }
template<typename T, typename V>
void FixedLengthEncoder< T, V >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 151 of file FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, FixedLengthEncoder< T, V >::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, 1, sizeof(T), f);
155  fread((int8_t*)&dataMax, 1, sizeof(T), f);
156  fread((int8_t*)&has_nulls, 1, sizeof(bool), f);
157  }
size_t num_elems_
Definition: Encoder.h:191
template<typename T, typename V>
void FixedLengthEncoder< T, V >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 125 of file FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, and FixedLengthEncoder< T, V >::has_nulls.

125  {
126  const auto that_typed = static_cast<const FixedLengthEncoder<T, V>&>(that);
127  if (that_typed.has_nulls) {
128  has_nulls = true;
129  }
130  dataMin = std::min(dataMin, that_typed.dataMin);
131  dataMax = std::max(dataMax, that_typed.dataMax);
132  }
template<typename T, typename V>
bool FixedLengthEncoder< T, V >::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 FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, ChunkStats::has_nulls, FixedLengthEncoder< T, V >::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  }
template<typename T, typename V>
void FixedLengthEncoder< T, V >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 99 of file FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, and FixedLengthEncoder< T, V >::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)
template<typename T, typename V>
void FixedLengthEncoder< T, V >::updateStats ( const double  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 110 of file FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, and FixedLengthEncoder< T, V >::has_nulls.

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

Implements Encoder.

Definition at line 120 of file FixedLengthEncoder.h.

References CHECK().

120  {
121  CHECK(false);
122  }
CHECK(cgen_state)

+ Here is the call graph for this function:

template<typename T, typename V>
void FixedLengthEncoder< T, V >::writeMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 143 of file FixedLengthEncoder.h.

References FixedLengthEncoder< T, V >::dataMax, FixedLengthEncoder< T, V >::dataMin, FixedLengthEncoder< T, V >::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

Member Data Documentation


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