OmniSciDB  0fdbebe030
 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 *&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 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 *&  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 DateDaysEncoder.h.

References Data_Namespace::AbstractBuffer::append(), Encoder::buffer_, CHECK(), CHECK_GE, 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, SQLTypeInfo::is_date_in_days(), Encoder::num_elems_, DateDaysOverflowValidator::validate(), and Data_Namespace::AbstractBuffer::write().

42  {
43  CHECK(ti.is_date_in_days());
44  T* unencoded_data = reinterpret_cast<T*>(src_data);
45  auto encoded_data = std::make_unique<V[]>(num_elems_to_append);
46  for (size_t i = 0; i < num_elems_to_append; ++i) {
47  size_t ri = replicating ? 0 : i;
48  if (unencoded_data[ri] == std::numeric_limits<V>::min()) {
49  has_nulls = true;
50  encoded_data.get()[i] = static_cast<V>(unencoded_data[ri]);
51  } else {
52  date_days_overflow_validator_.validate(unencoded_data[ri]);
53  encoded_data.get()[i] =
55  const T data = DateConverters::get_epoch_seconds_from_days(encoded_data.get()[i]);
56  dataMax = std::max(dataMax, data);
57  dataMin = std::min(dataMin, data);
58  }
59  }
60 
61  if (offset == -1) {
62  num_elems_ += num_elems_to_append;
63  buffer_->append(reinterpret_cast<int8_t*>(encoded_data.get()),
64  num_elems_to_append * sizeof(V));
65  if (!replicating) {
66  src_data += num_elems_to_append * sizeof(T);
67  }
68  } else {
69  num_elems_ = offset + num_elems_to_append;
70  CHECK(!replicating);
71  CHECK_GE(offset, 0);
72  buffer_->write(reinterpret_cast<int8_t*>(encoded_data.get()),
73  num_elems_to_append * sizeof(V),
74  static_cast<size_t>(offset));
75  }
76 
77  ChunkMetadata chunkMetadata;
78  getMetadata(chunkMetadata);
79  return chunkMetadata;
80  }
size_t num_elems_
Definition: Encoder.h:191
#define CHECK_GE(x, y)
Definition: Logger.h:210
int64_t get_epoch_seconds_from_days(const int64_t days)
CHECK(cgen_state)
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:193
void validate(T value)
Definition: Encoder.h:122
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
DateDaysOverflowValidator date_days_overflow_validator_
Definition: Encoder.h:197
bool is_date_in_days() const
Definition: sqltypes.h:611
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 130 of file DateDaysEncoder.h.

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

130  {
131  num_elems_ = copyFromEncoder->getNumElems();
132  auto castedEncoder = reinterpret_cast<const DateDaysEncoder<T, V>*>(copyFromEncoder);
133  dataMin = castedEncoder->dataMin;
134  dataMax = castedEncoder->dataMax;
135  has_nulls = castedEncoder->has_nulls;
136  }
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 DateDaysEncoder< T, V >::getMetadata ( ChunkMetadata chunkMetadata)
inlineoverridevirtual

Reimplemented from Encoder.

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

82  {
83  Encoder::getMetadata(chunkMetadata);
84  chunkMetadata.fillChunkStats(dataMin, dataMax, has_nulls);
85  }
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 88 of file DateDaysEncoder.h.

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

88  {
89  ChunkMetadata chunk_metadata{ti, 0, 0, ChunkStats{}};
90  chunk_metadata.fillChunkStats(dataMin, dataMax, has_nulls);
91  return chunk_metadata;
92  }
template<typename T, typename V>
void DateDaysEncoder< T, V >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 146 of file DateDaysEncoder.h.

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

146  {
147  // assumes pointer is already in right place
148  fread((int8_t*)&num_elems_, sizeof(size_t), 1, f);
149  fread((int8_t*)&dataMin, 1, sizeof(T), f);
150  fread((int8_t*)&dataMax, 1, sizeof(T), f);
151  fread((int8_t*)&has_nulls, 1, sizeof(bool), f);
152  }
size_t num_elems_
Definition: Encoder.h:191
template<typename T, typename V>
void DateDaysEncoder< T, V >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 121 of file DateDaysEncoder.h.

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

121  {
122  const auto that_typed = static_cast<const DateDaysEncoder<T, V>&>(that);
123  if (that_typed.has_nulls) {
124  has_nulls = true;
125  }
126  dataMin = std::min(dataMin, that_typed.dataMin);
127  dataMax = std::max(dataMax, that_typed.dataMax);
128  }
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 154 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.

154  {
155  const auto new_min = DatumFetcher::getDatumVal<T>(stats.min);
156  const auto new_max = DatumFetcher::getDatumVal<T>(stats.max);
157 
158  if (dataMin == new_min && dataMax == new_max && has_nulls == stats.has_nulls) {
159  return false;
160  }
161 
162  dataMin = new_min;
163  dataMax = new_max;
164  has_nulls = stats.has_nulls;
165  return true;
166  }
template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 95 of file DateDaysEncoder.h.

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

95  {
96  if (is_null) {
97  has_nulls = true;
98  } else {
99  const auto data = static_cast<T>(val);
100  dataMin = std::min(dataMin, data);
101  dataMax = std::max(dataMax, data);
102  }
103  }
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 106 of file DateDaysEncoder.h.

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

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

Implements Encoder.

Definition at line 116 of file DateDaysEncoder.h.

References CHECK().

116  {
117  CHECK(false);
118  }
CHECK(cgen_state)

+ Here is the call graph for this function:

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

Implements Encoder.

Definition at line 138 of file DateDaysEncoder.h.

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

138  {
139  // assumes pointer is already in right place
140  fwrite((int8_t*)&num_elems_, sizeof(size_t), 1, f);
141  fwrite((int8_t*)&dataMin, sizeof(T), 1, f);
142  fwrite((int8_t*)&dataMax, sizeof(T), 1, f);
143  fwrite((int8_t*)&has_nulls, sizeof(bool), 1, f);
144  }
size_t num_elems_
Definition: Encoder.h:191

Member Data Documentation


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