OmniSciDB  95562058bd
 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)
 
std::shared_ptr< ChunkMetadataappendData (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 (const std::shared_ptr< ChunkMetadata > &chunkMetadata) override
 
std::shared_ptr< ChunkMetadatagetMetadata (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 src_data, const size_t num_elements) override
 
void updateStats (const std::vector< std::string > *const src_data, const size_t start_idx, const size_t num_elements) override
 
void updateStats (const std::vector< ArrayDatum > *const src_data, const size_t start_idx, const size_t num_elements) 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
 

Private Member Functions

encodeDataAndUpdateStats (const T &unencoded_data)
 

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>
std::shared_ptr<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 >::encodeDataAndUpdateStats(), DateDaysEncoder< T, V >::getMetadata(), SQLTypeInfo::is_date_in_days(), Encoder::num_elems_, omnisci.dtypes::T, 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  encoded_data.get()[i] = encodeDataAndUpdateStats(unencoded_data[ri]);
49  }
50 
51  if (offset == -1) {
52  num_elems_ += num_elems_to_append;
53  buffer_->append(reinterpret_cast<int8_t*>(encoded_data.get()),
54  num_elems_to_append * sizeof(V));
55  if (!replicating) {
56  src_data += num_elems_to_append * sizeof(T);
57  }
58  } else {
59  num_elems_ = offset + num_elems_to_append;
60  CHECK(!replicating);
61  CHECK_GE(offset, 0);
62  buffer_->write(reinterpret_cast<int8_t*>(encoded_data.get()),
63  num_elems_to_append * sizeof(V),
64  static_cast<size_t>(offset));
65  }
66 
67  auto chunk_metadata = std::make_shared<ChunkMetadata>();
68  getMetadata(chunk_metadata);
69  return chunk_metadata;
70  }
size_t num_elems_
Definition: Encoder.h:218
#define CHECK_GE(x, y)
Definition: Logger.h:210
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:220
V encodeDataAndUpdateStats(const T &unencoded_data)
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 getMetadata(const std::shared_ptr< ChunkMetadata > &chunkMetadata) override
bool is_date_in_days() const
Definition: sqltypes.h:632
virtual void append(int8_t *src, const size_t num_bytes, const MemoryLevel src_buffer_type=CPU_LEVEL, const int device_id=-1)=0
#define CHECK(condition)
Definition: Logger.h:197

+ 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 135 of file DateDaysEncoder.h.

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

135  {
136  num_elems_ = copyFromEncoder->getNumElems();
137  auto castedEncoder = reinterpret_cast<const DateDaysEncoder<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:218
size_t getNumElems() const
Definition: Encoder.h:214

+ Here is the call graph for this function:

template<typename T, typename V>
V DateDaysEncoder< T, V >::encodeDataAndUpdateStats ( const T &  unencoded_data)
inlineprivate

Definition at line 178 of file DateDaysEncoder.h.

References 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 >::has_nulls, omnisci.dtypes::T, and DateDaysOverflowValidator::validate().

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

178  {
179  V encoded_data;
180  if (unencoded_data == std::numeric_limits<V>::min()) {
181  has_nulls = true;
182  encoded_data = static_cast<V>(unencoded_data);
183  } else {
184  date_days_overflow_validator_.validate(unencoded_data);
185  encoded_data = DateConverters::get_epoch_days_from_seconds(unencoded_data);
186  const T data = DateConverters::get_epoch_seconds_from_days(encoded_data);
187  dataMax = std::max(dataMax, data);
188  dataMin = std::min(dataMin, data);
189  }
190  return encoded_data;
191  }
int64_t get_epoch_seconds_from_days(const int64_t days)
void validate(T value)
Definition: Encoder.h:122
DateDaysOverflowValidator date_days_overflow_validator_
Definition: Encoder.h:223
int64_t get_epoch_days_from_seconds(const int64_t seconds)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Reimplemented from Encoder.

Definition at line 72 of file DateDaysEncoder.h.

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

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

72  {
73  Encoder::getMetadata(chunkMetadata);
74  chunkMetadata->fillChunkStats(dataMin, dataMax, has_nulls);
75  }
virtual void getMetadata(const std::shared_ptr< 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>
std::shared_ptr<ChunkMetadata> DateDaysEncoder< T, V >::getMetadata ( const SQLTypeInfo ti)
inlineoverridevirtual

Implements Encoder.

Definition at line 78 of file DateDaysEncoder.h.

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

78  {
79  auto chunk_metadata = std::make_shared<ChunkMetadata>(ti, 0, 0, ChunkStats{});
80  chunk_metadata->fillChunkStats(dataMin, dataMax, has_nulls);
81  return chunk_metadata;
82  }
template<typename T, typename V>
void DateDaysEncoder< T, V >::readMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 151 of file DateDaysEncoder.h.

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

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:218
template<typename T, typename V>
void DateDaysEncoder< T, V >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 126 of file DateDaysEncoder.h.

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

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

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 DateDaysEncoder< T, V >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 85 of file DateDaysEncoder.h.

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

85  {
86  if (is_null) {
87  has_nulls = true;
88  } else {
89  const auto data = static_cast<T>(val);
90  dataMin = std::min(dataMin, data);
91  dataMax = std::max(dataMax, data);
92  }
93  }
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 96 of file DateDaysEncoder.h.

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

96  {
97  if (is_null) {
98  has_nulls = true;
99  } else {
100  const auto data = static_cast<T>(val);
101  dataMin = std::min(dataMin, data);
102  dataMax = std::max(dataMax, data);
103  }
104  }
bool is_null(const T &v, const SQLTypeInfo &t)
template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const int8_t *const  src_data,
const size_t  num_elements 
)
inlineoverridevirtual

Update statistics for data without appending.

Parameters
src_data- the data with which to update statistics
num_elements- the number of elements to scan in the data

Implements Encoder.

Definition at line 106 of file DateDaysEncoder.h.

References DateDaysEncoder< T, V >::encodeDataAndUpdateStats(), and omnisci.dtypes::T.

106  {
107  const T* unencoded_data = reinterpret_cast<const T*>(src_data);
108  for (size_t i = 0; i < num_elements; ++i) {
109  encodeDataAndUpdateStats(unencoded_data[i]);
110  }
111  }
V encodeDataAndUpdateStats(const T &unencoded_data)

+ Here is the call graph for this function:

template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const std::vector< std::string > *const  src_data,
const size_t  start_idx,
const size_t  num_elements 
)
inlineoverridevirtual

Update statistics for string data without appending.

Parameters
src_data- the string data with which to update statistics
start_idx- the offset into src_data to start the update
num_elements- the number of elements to scan in the string data

Implements Encoder.

Definition at line 113 of file DateDaysEncoder.h.

References UNREACHABLE.

115  {
116  UNREACHABLE();
117  }
#define UNREACHABLE()
Definition: Logger.h:241
template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const std::vector< ArrayDatum > *const  src_data,
const size_t  start_idx,
const size_t  num_elements 
)
inlineoverridevirtual

Update statistics for array data without appending.

Parameters
src_data- the array data with which to update statistics
start_idx- the offset into src_data to start the update
num_elements- the number of elements to scan in the array data

Implements Encoder.

Definition at line 119 of file DateDaysEncoder.h.

References UNREACHABLE.

121  {
122  UNREACHABLE();
123  }
#define UNREACHABLE()
Definition: Logger.h:241
template<typename T, typename V>
void DateDaysEncoder< T, V >::writeMetadata ( FILE *  f)
inlineoverridevirtual

Implements Encoder.

Definition at line 143 of file DateDaysEncoder.h.

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

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:218

Member Data Documentation


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