OmniSciDB  ba1bac9284
 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...
 
void resetChunkStats () override
 
- Public Member Functions inherited from Encoder
 Encoder (Data_Namespace::AbstractBuffer *buffer)
 
virtual ~Encoder ()
 
virtual void updateStatsEncoded (const int8_t *const dst_data, const size_t num_elements)
 
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.

References DateDaysEncoder< T, V >::resetChunkStats().

32  : Encoder(buffer) {
34  }
void resetChunkStats() override
Encoder(Data_Namespace::AbstractBuffer *buffer)
Definition: Encoder.cpp:221

+ Here is the call graph for this function:

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

References Data_Namespace::AbstractBuffer::append(), Encoder::buffer_, CHECK, CHECK_GE, DateDaysEncoder< T, V >::encodeDataAndUpdateStats(), DateDaysEncoder< T, V >::getMetadata(), i, SQLTypeInfo::is_date_in_days(), Encoder::num_elems_, DateDaysEncoder< T, V >::resetChunkStats(), omnisci.dtypes::T, and Data_Namespace::AbstractBuffer::write().

40  {
41  CHECK(ti.is_date_in_days());
42  if (offset == 0 && num_elems_to_append >= num_elems_) {
44  }
45  T* unencoded_data = reinterpret_cast<T*>(src_data);
46  auto encoded_data = std::make_unique<V[]>(num_elems_to_append);
47  for (size_t i = 0; i < num_elems_to_append; ++i) {
48  size_t ri = replicating ? 0 : i;
49  encoded_data.get()[i] = encodeDataAndUpdateStats(unencoded_data[ri]);
50  }
51 
52  if (offset == -1) {
53  num_elems_ += num_elems_to_append;
54  buffer_->append(reinterpret_cast<int8_t*>(encoded_data.get()),
55  num_elems_to_append * sizeof(V));
56  if (!replicating) {
57  src_data += num_elems_to_append * sizeof(T);
58  }
59  } else {
60  num_elems_ = offset + num_elems_to_append;
61  CHECK(!replicating);
62  CHECK_GE(offset, 0);
63  buffer_->write(reinterpret_cast<int8_t*>(encoded_data.get()),
64  num_elems_to_append * sizeof(V),
65  static_cast<size_t>(offset));
66  }
67 
68  auto chunk_metadata = std::make_shared<ChunkMetadata>();
69  getMetadata(chunk_metadata);
70  return chunk_metadata;
71  }
size_t num_elems_
Definition: Encoder.h:237
#define CHECK_GE(x, y)
Definition: Logger.h:219
void resetChunkStats() override
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:239
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:721
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:206

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

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

136  {
137  num_elems_ = copyFromEncoder->getNumElems();
138  auto castedEncoder = reinterpret_cast<const DateDaysEncoder<T, V>*>(copyFromEncoder);
139  dataMin = castedEncoder->dataMin;
140  dataMax = castedEncoder->dataMax;
141  has_nulls = castedEncoder->has_nulls;
142  }
size_t num_elems_
Definition: Encoder.h:237
size_t getNumElems() const
Definition: Encoder.h:233

+ 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 185 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().

185  {
186  V encoded_data;
187  if (unencoded_data == std::numeric_limits<V>::min()) {
188  has_nulls = true;
189  encoded_data = static_cast<V>(unencoded_data);
190  } else {
191  date_days_overflow_validator_.validate(unencoded_data);
192  encoded_data = DateConverters::get_epoch_days_from_seconds(unencoded_data);
193  const T data = DateConverters::get_epoch_seconds_from_days(encoded_data);
194  dataMax = std::max(dataMax, data);
195  dataMin = std::min(dataMin, data);
196  }
197  return encoded_data;
198  }
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:242
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 73 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().

73  {
74  Encoder::getMetadata(chunkMetadata);
75  chunkMetadata->fillChunkStats(dataMin, dataMax, has_nulls);
76  }
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 79 of file DateDaysEncoder.h.

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

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

Implements Encoder.

Definition at line 152 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.

152  {
153  // assumes pointer is already in right place
154  fread((int8_t*)&num_elems_, sizeof(size_t), 1, f);
155  fread((int8_t*)&dataMin, 1, sizeof(T), f);
156  fread((int8_t*)&dataMax, 1, sizeof(T), f);
157  fread((int8_t*)&has_nulls, 1, sizeof(bool), f);
158  }
size_t num_elems_
Definition: Encoder.h:237
char * f
template<typename T, typename V>
void DateDaysEncoder< T, V >::reduceStats ( const Encoder that)
inlineoverridevirtual

Implements Encoder.

Definition at line 127 of file DateDaysEncoder.h.

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

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

160  {
161  const auto new_min = DatumFetcher::getDatumVal<T>(stats.min);
162  const auto new_max = DatumFetcher::getDatumVal<T>(stats.max);
163 
164  if (dataMin == new_min && dataMax == new_max && has_nulls == stats.has_nulls) {
165  return false;
166  }
167 
168  dataMin = new_min;
169  dataMax = new_max;
170  has_nulls = stats.has_nulls;
171  return true;
172  }
template<typename T, typename V>
void DateDaysEncoder< T, V >::resetChunkStats ( )
inlineoverridevirtual

Resets chunk metadata stats to their default values.

Implements Encoder.

Definition at line 174 of file DateDaysEncoder.h.

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

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

174  {
175  dataMin = std::numeric_limits<T>::max();
176  dataMax = std::numeric_limits<T>::lowest();
177  has_nulls = false;
178  }

+ Here is the caller graph for this function:

template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const int64_t  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 86 of file DateDaysEncoder.h.

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

86  {
87  if (is_null) {
88  has_nulls = true;
89  } else {
90  const auto data = static_cast<T>(val);
91  dataMin = std::min(dataMin, data);
92  dataMax = std::max(dataMax, data);
93  }
94  }
CONSTEXPR DEVICE bool is_null(const T &value)
template<typename T, typename V>
void DateDaysEncoder< T, V >::updateStats ( const double  val,
const bool  is_null 
)
inlineoverridevirtual

Implements Encoder.

Definition at line 97 of file DateDaysEncoder.h.

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

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

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

107  {
108  const T* unencoded_data = reinterpret_cast<const T*>(src_data);
109  for (size_t i = 0; i < num_elements; ++i) {
110  encodeDataAndUpdateStats(unencoded_data[i]);
111  }
112  }
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 114 of file DateDaysEncoder.h.

References UNREACHABLE.

116  {
117  UNREACHABLE();
118  }
#define UNREACHABLE()
Definition: Logger.h:250
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 120 of file DateDaysEncoder.h.

References UNREACHABLE.

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

Implements Encoder.

Definition at line 144 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.

144  {
145  // assumes pointer is already in right place
146  fwrite((int8_t*)&num_elems_, sizeof(size_t), 1, f);
147  fwrite((int8_t*)&dataMin, sizeof(T), 1, f);
148  fwrite((int8_t*)&dataMax, sizeof(T), 1, f);
149  fwrite((int8_t*)&has_nulls, sizeof(bool), 1, f);
150  }
size_t num_elems_
Definition: Encoder.h:237
char * f

Member Data Documentation


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