OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{TypedDataAccessors.h} Namespace Reference

Classes

class  NullSentinelSupplier
 

Functions

template<typename LHT , typename RHT >
void value_truncated (const LHT &lhs, const RHT &rhs)
 
template<typename T >
bool is_null (const T &v, const SQLTypeInfo &t)
 
template<typename LHT , typename RHT >
bool integer_setter (LHT &lhs, const RHT &rhs, const SQLTypeInfo &t)
 
int get_element_size (const SQLTypeInfo &t)
 
bool is_null_string_index (const int size, const int32_t sidx)
 
int32_t get_string_index (void *ptr, const int size)
 
bool set_string_index (void *ptr, const SQLTypeInfo &etype, int32_t sidx)
 
template<typename T >
static void put_scalar (void *ndptr, const SQLTypeInfo &etype, const int esize, const T oval)
 
double decimal_to_double (const SQLTypeInfo &otype, int64_t oval)
 
template<typename T >
void put_scalar (void *ndptr, const SQLTypeInfo &ntype, const T oval, const std::string col_name, const SQLTypeInfo *otype=nullptr)
 
void put_null (void *ndptr, const SQLTypeInfo &ntype, const std::string col_name)
 
void put_null_array (void *ndptr, const SQLTypeInfo &ntype, const std::string col_name)
 
template<typename T >
bool get_scalar (void *ndptr, const SQLTypeInfo &ntype, T &v)
 
template<typename T >
void set_minmax (T &min, T &max, T const val)
 
template<typename T >
void set_minmax (T &min, T &max, bool &null_flag, T const val, T null_sentinel)
 

Function Documentation

double anonymous_namespace{TypedDataAccessors.h}::decimal_to_double ( const SQLTypeInfo otype,
int64_t  oval 
)
inline

Definition at line 185 of file TypedDataAccessors.h.

References SQLTypeInfo::get_scale().

Referenced by put_scalar(), and Fragmenter_Namespace::InsertOrderFragmenter::updateColumn().

185  {
186  return oval / pow(10, otype.get_scale());
187 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int anonymous_namespace{TypedDataAccessors.h}::get_element_size ( const SQLTypeInfo t)
inline

Definition at line 67 of file TypedDataAccessors.h.

References SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_size(), SQLTypeInfo::get_subtype(), SQLTypeInfo::is_array(), SQLTypeInfo::is_string_array(), and kNULLT.

67  {
68  if (t.is_string_array()) {
69  return sizeof(int32_t);
70  }
71  if (!t.is_array()) {
72  return t.get_size();
73  }
74  return SQLTypeInfo(t.get_subtype(),
75  t.get_dimension(),
76  t.get_scale(),
77  false,
78  t.get_compression(),
79  t.get_comp_param(),
80  kNULLT)
81  .get_size();
82 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:392
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:393
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
bool is_string_array() const
Definition: sqltypes.h:564
bool is_array() const
Definition: sqltypes.h:585

+ Here is the call graph for this function:

template<typename T >
bool anonymous_namespace{TypedDataAccessors.h}::get_scalar ( void *  ndptr,
const SQLTypeInfo ntype,
T &  v 
)
inline

Definition at line 355 of file TypedDataAccessors.h.

References SQLTypeInfo::get_size(), get_string_index(), SQLTypeInfo::get_type(), inline_fp_null_value< double >(), inline_fp_null_value< float >(), is_null_string_index(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, and kTINYINT.

355  {
356  switch (ntype.get_type()) {
357  case kBOOLEAN:
358  case kTINYINT:
359  case kSMALLINT:
360  case kINT:
361  case kBIGINT:
362  case kTIME:
363  case kTIMESTAMP:
364  case kDATE:
365  case kINTERVAL_DAY_TIME:
367  case kNUMERIC:
368  case kDECIMAL:
369  switch (ntype.get_size()) {
370  case 1:
371  return inline_int_null_value<int8_t>() == (v = *(int8_t*)ndptr);
372  case 2:
373  return inline_int_null_value<int16_t>() == (v = *(int16_t*)ndptr);
374  case 4:
375  return inline_int_null_value<int32_t>() == (v = *(int32_t*)ndptr);
376  case 8:
377  return inline_int_null_value<int64_t>() == (v = *(int64_t*)ndptr);
378  break;
379  default:
380  abort();
381  }
382  break;
383  case kFLOAT:
384  return inline_fp_null_value<float>() == (v = *(float*)ndptr);
385  case kDOUBLE:
386  return inline_fp_null_value<double>() == (v = *(double*)ndptr);
387  case kTEXT:
388  v = get_string_index(ndptr, ntype.get_size());
389  return is_null_string_index(ntype.get_size(), v);
390  default:
391  abort();
392  }
393 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
Definition: sqltypes.h:76
constexpr T inline_fp_null_value()
bool is_null_string_index(const int size, const int32_t sidx)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
Definition: sqltypes.h:79
Definition: sqltypes.h:80
constexpr int64_t inline_int_null_value()
Definition: sqltypes.h:72
int32_t get_string_index(void *ptr, const int size)

+ Here is the call graph for this function:

int32_t anonymous_namespace{TypedDataAccessors.h}::get_string_index ( void *  ptr,
const int  size 
)
inline

Definition at line 97 of file TypedDataAccessors.h.

Referenced by get_scalar().

97  {
98  switch (size) {
99  case 1:
100  return *(uint8_t*)ptr;
101  case 2:
102  return *(uint16_t*)ptr;
103  case 4:
104  return *(int32_t*)ptr;
105  default:
106  abort();
107  }
108 }

+ Here is the caller graph for this function:

template<typename LHT , typename RHT >
bool anonymous_namespace{TypedDataAccessors.h}::integer_setter ( LHT &  lhs,
const RHT &  rhs,
const SQLTypeInfo t 
)
inline

Definition at line 59 of file TypedDataAccessors.h.

References is_null(), and value_truncated().

Referenced by put_scalar(), and set_string_index().

59  {
60  const int64_t r = is_null(rhs, t) ? inline_int_null_value<LHT>() : rhs;
61  if ((lhs = r) != r) {
62  value_truncated(lhs, r);
63  }
64  return true;
65 }
void value_truncated(const LHT &lhs, const RHT &rhs)
CONSTEXPR DEVICE bool is_null(const T &value)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
bool anonymous_namespace{TypedDataAccessors.h}::is_null ( const T &  v,
const SQLTypeInfo t 
)
inline

Definition at line 40 of file TypedDataAccessors.h.

References SQLTypeInfo::get_logical_size().

40  {
41  if (std::is_floating_point<T>::value) {
42  return v == inline_fp_null_value<T>();
43  }
44  switch (t.get_logical_size()) {
45  case 1:
46  return v == inline_int_null_value<int8_t>();
47  case 2:
48  return v == inline_int_null_value<int16_t>();
49  case 4:
50  return v == inline_int_null_value<int32_t>();
51  case 8:
52  return v == inline_int_null_value<int64_t>();
53  default:
54  abort();
55  }
56 }
int get_logical_size() const
Definition: sqltypes.h:421

+ Here is the call graph for this function:

bool anonymous_namespace{TypedDataAccessors.h}::is_null_string_index ( const int  size,
const int32_t  sidx 
)
inline

Definition at line 84 of file TypedDataAccessors.h.

Referenced by get_scalar().

84  {
85  switch (size) {
86  case 1:
87  return sidx == inline_int_null_value<uint8_t>();
88  case 2:
89  return sidx == inline_int_null_value<uint16_t>();
90  case 4:
91  return sidx == inline_int_null_value<int32_t>();
92  default:
93  abort();
94  }
95 }

+ Here is the caller graph for this function:

void anonymous_namespace{TypedDataAccessors.h}::put_null ( void *  ndptr,
const SQLTypeInfo ntype,
const std::string  col_name 
)
inline

this f is currently only for putting fixed-size data in place this f is not yet for putting var-size or dict-encoded data

Definition at line 254 of file TypedDataAccessors.h.

References CHECK, SQLTypeInfo::get_notnull(), SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), inline_fp_null_value< double >(), inline_fp_null_value< float >(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, and kTINYINT.

Referenced by RelAlgExecutor::executeSimpleInsert(), and Fragmenter_Namespace::InsertOrderFragmenter::updateColumn().

254  {
255  if (ntype.get_notnull()) {
256  throw std::runtime_error("NULL value on NOT NULL column '" + col_name + "'");
257  }
258 
259  switch (ntype.get_type()) {
260  case kBOOLEAN:
261  case kTINYINT:
262  case kSMALLINT:
263  case kINT:
264  case kBIGINT:
265  case kTIME:
266  case kTIMESTAMP:
267  case kDATE:
268  case kINTERVAL_DAY_TIME:
270  case kNUMERIC:
271  case kDECIMAL:
272  case kTEXT:
273  switch (ntype.get_size()) {
274  case 1:
275  *(int8_t*)ndptr = inline_int_null_value<int8_t>();
276  break;
277  case 2:
278  *(int16_t*)ndptr = inline_int_null_value<int16_t>();
279  break;
280  case 4:
281  *(int32_t*)ndptr = inline_int_null_value<int32_t>();
282  break;
283  case 8:
284  *(int64_t*)ndptr = inline_int_null_value<int64_t>();
285  break;
286  default:
287  abort();
288  }
289  break;
290  case kFLOAT:
291  *(float*)ndptr = inline_fp_null_value<float>();
292  break;
293  case kDOUBLE:
294  *(double*)ndptr = inline_fp_null_value<double>();
295  break;
296  default:
299  CHECK(false);
300  }
301 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
Definition: sqltypes.h:76
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
Definition: sqltypes.h:79
Definition: sqltypes.h:80
constexpr float inline_fp_null_value< float >()
constexpr double inline_fp_null_value< double >()
#define CHECK(condition)
Definition: Logger.h:291
Definition: sqltypes.h:72
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{TypedDataAccessors.h}::put_null_array ( void *  ndptr,
const SQLTypeInfo ntype,
const std::string  col_name 
)
inline

this f is currently only for putting fixed-size data in place this f is not yet for putting var-size or dict-encoded data

Definition at line 303 of file TypedDataAccessors.h.

References CHECK, SQLTypeInfo::get_notnull(), SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), inline_fp_null_array_value< double >(), inline_fp_null_array_value< float >(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, and kTINYINT.

Referenced by RelAlgExecutor::executeSimpleInsert().

305  {
306  if (ntype.get_notnull()) {
307  throw std::runtime_error("NULL value on NOT NULL column '" + col_name + "'");
308  }
309 
310  switch (ntype.get_type()) {
311  case kBOOLEAN:
312  case kTINYINT:
313  case kSMALLINT:
314  case kINT:
315  case kBIGINT:
316  case kTIME:
317  case kTIMESTAMP:
318  case kDATE:
319  case kINTERVAL_DAY_TIME:
321  case kNUMERIC:
322  case kDECIMAL:
323  case kTEXT:
324  switch (ntype.get_size()) {
325  case 1:
326  *(int8_t*)ndptr = inline_int_null_array_value<int8_t>();
327  break;
328  case 2:
329  *(int16_t*)ndptr = inline_int_null_array_value<int16_t>();
330  break;
331  case 4:
332  *(int32_t*)ndptr = inline_int_null_array_value<int32_t>();
333  break;
334  case 8:
335  *(int64_t*)ndptr = inline_int_null_array_value<int64_t>();
336  break;
337  default:
338  abort();
339  }
340  break;
341  case kFLOAT:
342  *(float*)ndptr = inline_fp_null_array_value<float>();
343  break;
344  case kDOUBLE:
345  *(double*)ndptr = inline_fp_null_array_value<double>();
346  break;
347  default:
350  CHECK(false);
351  }
352 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
Definition: sqltypes.h:76
DEVICE float inline_fp_null_array_value< float >()
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
DEVICE double inline_fp_null_array_value< double >()
Definition: sqltypes.h:79
Definition: sqltypes.h:80
#define CHECK(condition)
Definition: Logger.h:291
Definition: sqltypes.h:72
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
static void anonymous_namespace{TypedDataAccessors.h}::put_scalar ( void *  ndptr,
const SQLTypeInfo etype,
const int  esize,
const T  oval 
)
static

Definition at line 127 of file TypedDataAccessors.h.

References SQLTypeInfo::get_type(), integer_setter(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_string(), SQLTypeInfo::is_time(), SQLTypeInfo::is_timeinterval(), SQLTypeInfo::is_varlen(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, and set_string_index().

130  {
131  // round floating oval to nearest integer
132  auto rval = oval;
133  if (std::is_floating_point<T>::value) {
134  if (etype.is_integer() || etype.is_time() || etype.is_timeinterval() ||
135  etype.is_decimal()) {
136  rval = round(rval);
137  }
138  }
139  switch (etype.get_type()) {
140  case kBOOLEAN:
141  case kTIME:
142  case kTIMESTAMP:
143  case kDATE:
144  case kTINYINT:
145  case kSMALLINT:
146  case kINT:
147  case kBIGINT:
148  case kINTERVAL_DAY_TIME:
150  case kNUMERIC:
151  case kDECIMAL:
152  switch (esize) {
153  case 1:
154  integer_setter(*(int8_t*)ndptr, rval, etype);
155  break;
156  case 2:
157  integer_setter(*(int16_t*)ndptr, rval, etype);
158  break;
159  case 4:
160  integer_setter(*(int32_t*)ndptr, rval, etype);
161  break;
162  case 8:
163  integer_setter(*(int64_t*)ndptr, rval, etype);
164  break;
165  default:
166  abort();
167  }
168  break;
169  case kFLOAT:
170  *(float*)ndptr = rval;
171  break;
172  case kDOUBLE:
173  *(double*)ndptr = rval;
174  break;
175  default:
176  if (etype.is_string() && !etype.is_varlen()) {
177  set_string_index(ndptr, etype, rval);
178  } else {
179  abort();
180  }
181  break;
182  }
183 }
Definition: sqltypes.h:76
bool is_varlen() const
Definition: sqltypes.h:631
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
bool is_time() const
Definition: sqltypes.h:579
bool is_integer() const
Definition: sqltypes.h:567
bool is_timeinterval() const
Definition: sqltypes.h:594
Definition: sqltypes.h:80
bool set_string_index(void *ptr, const SQLTypeInfo &etype, int32_t sidx)
bool integer_setter(LHT &lhs, const RHT &rhs, const SQLTypeInfo &t)
Definition: sqltypes.h:72
bool is_string() const
Definition: sqltypes.h:561
bool is_decimal() const
Definition: sqltypes.h:570

+ Here is the call graph for this function:

template<typename T >
void anonymous_namespace{TypedDataAccessors.h}::put_scalar ( void *  ndptr,
const SQLTypeInfo ntype,
const T  oval,
const std::string  col_name,
const SQLTypeInfo otype = nullptr 
)
inline

Definition at line 190 of file TypedDataAccessors.h.

References convert_decimal_value_to_scale(), decimal_to_double(), SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_dimension(), anonymous_namespace{ResultSetReductionInterpreter.cpp}::get_element_size(), DateConverters::get_epoch_days_from_seconds(), SQLTypeInfo::get_notnull(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_subtype(), SQLTypeInfo::is_array(), is_null(), kDATE, kDECIMAL, kNULLT, and kNUMERIC.

194  {
195  const auto& etype = ntype.is_array() ? SQLTypeInfo(ntype.get_subtype(),
196  ntype.get_dimension(),
197  ntype.get_scale(),
198  ntype.get_notnull(),
199  ntype.get_compression(),
200  ntype.get_comp_param(),
201  kNULLT)
202  : ntype;
203  const auto esize = get_element_size(etype);
204  const auto isnull = is_null(oval, etype);
205  if (etype.get_notnull() && isnull) {
206  throw std::runtime_error("NULL value on NOT NULL column '" + col_name + "'");
207  }
208 
209  switch (etype.get_type()) {
210  case kNUMERIC:
211  case kDECIMAL:
212  if (otype && otype->is_decimal()) {
213  put_scalar<int64_t>(ndptr,
214  etype,
215  esize,
216  isnull ? inline_int_null_value<int64_t>()
217  : convert_decimal_value_to_scale(oval, *otype, etype));
218  } else {
219  put_scalar<T>(ndptr,
220  etype,
221  esize,
222  isnull ? inline_int_null_value<int64_t>()
223  : oval * pow(10, etype.get_scale()));
224  }
225  break;
226  case kDATE:
227  // For small dates, we store in days but decode in seconds
228  // therefore we have to scale the decoded value in order to
229  // make value storable.
230  // Should be removed when we refactor code to use DateConverterFactory
231  // from TargetValueConverterFactories so that we would
232  // have everything in one place.
233  if (etype.is_date_in_days()) {
234  put_scalar<T>(ndptr,
235  etype,
236  get_element_size(etype),
237  isnull ? inline_int_null_value<int64_t>()
239  static_cast<int64_t>(oval)));
240  } else {
241  put_scalar<T>(ndptr, etype, get_element_size(etype), oval);
242  }
243  break;
244  default:
245  if (otype && otype->is_decimal()) {
246  put_scalar<double>(ndptr, etype, decimal_to_double(*otype, oval), col_name);
247  } else {
248  put_scalar<T>(ndptr, etype, get_element_size(etype), oval);
249  }
250  break;
251  }
252 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:392
double decimal_to_double(const SQLTypeInfo &otype, int64_t oval)
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
CONSTEXPR DEVICE bool is_null(const T &value)
Definition: sqltypes.h:80
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:624
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:393
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
int64_t get_epoch_days_from_seconds(const int64_t seconds)
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
bool is_decimal() const
Definition: sqltypes.h:570
bool is_array() const
Definition: sqltypes.h:585

+ Here is the call graph for this function:

template<typename T >
void anonymous_namespace{TypedDataAccessors.h}::set_minmax ( T &  min,
T &  max,
T const  val 
)
inline

Definition at line 422 of file TypedDataAccessors.h.

Referenced by Fragmenter_Namespace::set_chunk_stats(), and Fragmenter_Namespace::anonymous_namespace{UpdelStorage.cpp}::update_metadata().

422  {
423  if (val < min) {
424  min = val;
425  }
426  if (val > max) {
427  max = val;
428  }
429 }

+ Here is the caller graph for this function:

template<typename T >
void anonymous_namespace{TypedDataAccessors.h}::set_minmax ( T &  min,
T &  max,
bool &  null_flag,
T const  val,
null_sentinel 
)
inline

Definition at line 432 of file TypedDataAccessors.h.

432  {
433  if (val == null_sentinel) {
434  null_flag = true;
435  } else {
436  if (val < min) {
437  min = val;
438  }
439  if (val > max) {
440  max = val;
441  }
442  }
443 }
bool anonymous_namespace{TypedDataAccessors.h}::set_string_index ( void *  ptr,
const SQLTypeInfo etype,
int32_t  sidx 
)
inline

Definition at line 110 of file TypedDataAccessors.h.

References anonymous_namespace{ResultSetReductionInterpreter.cpp}::get_element_size(), and integer_setter().

Referenced by put_scalar().

110  {
111  switch (get_element_size(etype)) {
112  case 1:
113  return integer_setter(*(uint8_t*)ptr, sidx, etype);
114  break;
115  case 2:
116  return integer_setter(*(uint16_t*)ptr, sidx, etype);
117  break;
118  case 4:
119  return integer_setter(*(int32_t*)ptr, sidx, etype);
120  break;
121  default:
122  abort();
123  }
124 }
bool integer_setter(LHT &lhs, const RHT &rhs, const SQLTypeInfo &t)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename LHT , typename RHT >
void anonymous_namespace{TypedDataAccessors.h}::value_truncated ( const LHT &  lhs,
const RHT &  rhs 
)
inline

Definition at line 30 of file TypedDataAccessors.h.

Referenced by integer_setter().

30  {
31  std::ostringstream os;
32  os << "Value " << rhs << " would be truncated to "
33  << (std::is_same<LHT, uint8_t>::value || std::is_same<LHT, int8_t>::value
34  ? (int64_t)lhs
35  : lhs);
36  throw std::runtime_error(os.str());
37 };

+ Here is the caller graph for this function: