OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DateDaysEncoder< T, V > Class Template Reference

#include <DateDaysEncoder.h>

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

Public Member Functions

 DateDaysEncoder (Data_Namespace::AbstractBuffer *buffer)
 
ChunkMetadata appendData (int8_t *&srcData, const size_t numAppendElems, const SQLTypeInfo &ti, 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 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 DateDaysEncoder< T, V >

Definition at line 30 of file DateDaysEncoder.h.

Constructor & Destructor Documentation

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

Definition at line 32 of file DateDaysEncoder.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 DateDaysEncoder< T, V >::appendData ( int8_t *&  srcData,
const size_t  numAppendElems,
const SQLTypeInfo ti,
const bool  replicating = false 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 38 of file DateDaysEncoder.h.

References Data_Namespace::AbstractBuffer::append(), Encoder::buffer_, CHECK(), DateDaysEncoder< T, V >::dataMax, DateDaysEncoder< T, V >::dataMin, Encoder::date_days_overflow_validator_, DateConverters::get_epoch_days_from_seconds(), DateConverters::get_epoch_seconds_from_days(), DateDaysEncoder< T, V >::getMetadata(), DateDaysEncoder< T, V >::has_nulls, Encoder::num_elems_, and DateDaysOverflowValidator::validate().

41  {
42  CHECK(ti.is_date_in_days());
43  T* unencodedData = reinterpret_cast<T*>(srcData);
44  auto encodedData = std::make_unique<V[]>(numAppendElems);
45  for (size_t i = 0; i < numAppendElems; ++i) {
46  size_t ri = replicating ? 0 : i;
47  if (unencodedData[ri] == std::numeric_limits<V>::min()) {
48  has_nulls = true;
49  encodedData.get()[i] = static_cast<V>(unencodedData[ri]);
50  } else {
51  date_days_overflow_validator_.validate(unencodedData[ri]);
52  encodedData.get()[i] =
54  const T data = DateConverters::get_epoch_seconds_from_days(encodedData.get()[i]);
55  dataMax = std::max(dataMax, data);
56  dataMin = std::min(dataMin, data);
57  }
58  }
59  num_elems_ += numAppendElems;
60 
61  buffer_->append((int8_t*)(encodedData.get()), numAppendElems * sizeof(V));
62  ChunkMetadata chunkMetadata;
63  getMetadata(chunkMetadata);
64  if (!replicating) {
65  srcData += numAppendElems * sizeof(T);
66  }
67  return chunkMetadata;
68  }
size_t num_elems_
Definition: Encoder.h:179
int64_t get_epoch_seconds_from_days(const int64_t days)
CHECK(cgen_state)
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:181
void validate(T value)
Definition: Encoder.h:122
DateDaysOverflowValidator date_days_overflow_validator_
Definition: Encoder.h:185
virtual void append(int8_t *src, const size_t num_bytes, const MemoryLevel src_buffer_type=CPU_LEVEL, const int device_id=-1)=0
int64_t get_epoch_days_from_seconds(const int64_t seconds)
void getMetadata(ChunkMetadata &chunkMetadata) override

+ Here is the call graph for this function:

template<typename T, typename V>
void DateDaysEncoder< T, V >::copyMetadata ( const Encoder copyFromEncoder)
inlineoverridevirtual

Implements Encoder.

Definition at line 114 of file DateDaysEncoder.h.

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

114  {
115  num_elems_ = copyFromEncoder->getNumElems();
116  auto castedEncoder = reinterpret_cast<const DateDaysEncoder<T, V>*>(copyFromEncoder);
117  dataMin = castedEncoder->dataMin;
118  dataMax = castedEncoder->dataMax;
119  has_nulls = castedEncoder->has_nulls;
120  }
size_t num_elems_
Definition: Encoder.h:179
size_t getNumElems() const
Definition: Encoder.h:175

+ Here is the call graph for this function:

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

Reimplemented from Encoder.

Definition at line 70 of file DateDaysEncoder.h.

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

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

70  {
71  Encoder::getMetadata(chunkMetadata);
72  chunkMetadata.fillChunkStats(dataMin, dataMax, has_nulls);
73  }
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 DateDaysEncoder< T, V >::getMetadata ( const SQLTypeInfo ti)
inlineoverridevirtual

Implements Encoder.

Definition at line 76 of file DateDaysEncoder.h.

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

76  {
77  ChunkMetadata chunk_metadata{ti, 0, 0, ChunkStats{}};
78  chunk_metadata.fillChunkStats(dataMin, dataMax, has_nulls);
79  return chunk_metadata;
80  }
template<typename T, typename V>
void DateDaysEncoder< T, V >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 130 of file DateDaysEncoder.h.

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

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

Implements Encoder.

Definition at line 105 of file DateDaysEncoder.h.

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

105  {
106  const auto that_typed = static_cast<const DateDaysEncoder<T, V>&>(that);
107  if (that_typed.has_nulls) {
108  has_nulls = true;
109  }
110  dataMin = std::min(dataMin, that_typed.dataMin);
111  dataMax = std::max(dataMax, that_typed.dataMax);
112  }
template<typename T, typename V>
bool DateDaysEncoder< 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 138 of file DateDaysEncoder.h.

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

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

Implements Encoder.

Definition at line 83 of file DateDaysEncoder.h.

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

83  {
84  if (is_null) {
85  has_nulls = true;
86  } else {
87  const auto data = static_cast<T>(val);
88  dataMin = std::min(dataMin, data);
89  dataMax = std::max(dataMax, data);
90  }
91  }
bool is_null(const T &v, const SQLTypeInfo &t)
template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const double  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 94 of file DateDaysEncoder.h.

References DateDaysEncoder< T, V >::dataMax, DateDaysEncoder< T, V >::dataMin, and DateDaysEncoder< T, V >::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)
template<typename T, typename V>
void DateDaysEncoder< T, V >::writeMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 122 of file DateDaysEncoder.h.

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

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

Member Data Documentation


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