OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SqlTypesLayout.h File Reference
#include "../Shared/TargetInfo.h"
#include "Logger.h"
#include <limits>
+ Include dependency graph for SqlTypesLayout.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  OverflowOrUnderflow
 

Functions

const SQLTypeInfo get_compact_type (const TargetInfo &target)
 
void set_compact_type (TargetInfo &target, const SQLTypeInfo &new_type)
 
int64_t inline_int_null_val (const SQLTypeInfo &ti)
 
int64_t inline_fixed_encoding_null_val (const SQLTypeInfo &ti)
 
double inline_fp_null_val (const SQLTypeInfo &ti)
 
uint64_t exp_to_scale (const unsigned exp)
 
size_t get_bit_width (const SQLTypeInfo &ti)
 
bool is_unsigned_type (const SQLTypeInfo &ti)
 

Detailed Description

Author
Alex Suhan alex@.nosp@m.mapd.nosp@m..com

Definition in file SqlTypesLayout.h.

Function Documentation

uint64_t exp_to_scale ( const unsigned  exp)
inline

Definition at line 159 of file SqlTypesLayout.h.

References run_benchmark_import::res.

Referenced by CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenCmpDecimalConst(), CodeGenerator::codegenDeciDiv(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), getExpressionRange(), anonymous_namespace{RelAlgTranslator.cpp}::makeNumericConstant(), ResultSet::makeTargetValue(), pair_to_double(), and anonymous_namespace{ExpressionRange.cpp}::scale_up_interval_endpoint().

159  {
160  uint64_t res = 1;
161  for (unsigned i = 0; i < exp; ++i) {
162  res *= 10;
163  }
164  return res;
165 }

+ Here is the caller graph for this function:

size_t get_bit_width ( const SQLTypeInfo ti)
inline

Definition at line 167 of file SqlTypesLayout.h.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_decimal(), kARRAY, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kLINESTRING, kMULTIPOLYGON, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, and kVARCHAR.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenHoistedConstantsLoads(), ColSlotContext::ColSlotContext(), TableFunctionExecutionContext::execute(), TableFunctionCompilationContext::generateEntryPoint(), get_agg_initial_val(), anonymous_namespace{ColumnIR.cpp}::get_col_bit_width(), get_col_byte_widths(), anonymous_namespace{QueryMemoryDescriptor.cpp}::is_int_and_no_bigger_than(), and lazy_decode().

167  {
168  const auto int_type = ti.is_decimal() ? kBIGINT : ti.get_type();
169  switch (int_type) {
170  case kBOOLEAN:
171  return 8;
172  case kTINYINT:
173  return 8;
174  case kSMALLINT:
175  return 16;
176  case kINT:
177  return 32;
178  case kBIGINT:
179  return 64;
180  case kFLOAT:
181  return 32;
182  case kDOUBLE:
183  return 64;
184  case kTIME:
185  case kTIMESTAMP:
186  case kDATE:
187  case kINTERVAL_DAY_TIME:
189  return sizeof(time_t) * 8;
190  case kTEXT:
191  case kVARCHAR:
192  case kCHAR:
193  return 32;
194  case kARRAY:
195  if (ti.get_size() == -1) {
196  throw std::runtime_error("Projecting on unsized array column not supported.");
197  }
198  return ti.get_size() * 8;
199  case kPOINT:
200  case kLINESTRING:
201  case kPOLYGON:
202  case kMULTIPOLYGON:
203  return 32;
204  default:
205  abort();
206  }
207 }
Definition: sqltypes.h:52
HOST DEVICE int get_size() const
Definition: sqltypes.h:336
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
Definition: sqltypes.h:55
Definition: sqltypes.h:56
Definition: sqltypes.h:44
Definition: sqltypes.h:48
bool is_decimal() const
Definition: sqltypes.h:480

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const SQLTypeInfo get_compact_type ( const TargetInfo target)
inline

Definition at line 36 of file SqlTypesLayout.h.

References agg_arg(), TargetInfo::agg_arg_type, TargetInfo::agg_kind, CHECK(), CHECK_EQ, TargetInfo::is_agg, is_agg_domain_range_equivalent(), TargetInfo::is_distinct, kCOUNT, kNULLT, SQLTypeInfoCore< TYPE_FACET_PACK >::set_notnull(), and TargetInfo::sql_type.

Referenced by anonymous_namespace{TargetExprBuilder.cpp}::agg_fn_base_names(), baseline_sort(), anonymous_namespace{ResultSetSortImpl.cu}::baseline_sort_int(), TargetExprCodegen::codegen(), ColSlotContext::ColSlotContext(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_value(), get_col_byte_widths(), GroupByAndAggregate::getKeylessInfo(), anonymous_namespace{OutputBufferInitialization.cpp}::init_agg_val_vec(), ResultSet::makeTargetValue(), ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::operator()(), ResultSetStorage::reduceSingleRow(), and set_notnull().

36  {
37  if (!target.is_agg) {
38  return target.sql_type;
39  }
40  const auto agg_type = target.agg_kind;
41  const auto& agg_arg = target.agg_arg_type;
42  if (agg_arg.get_type() == kNULLT) {
43  CHECK_EQ(kCOUNT, agg_type);
44  CHECK(!target.is_distinct);
45  return target.sql_type;
46  }
47 
48  if (is_agg_domain_range_equivalent(agg_type)) {
49  return agg_arg;
50  } else {
51  // Nullability of the target needs to match that of the agg for proper initialization
52  // of target (aggregate) values
53  auto modified_target_type = target.sql_type;
54  modified_target_type.set_notnull(agg_arg.get_notnull());
55  return modified_target_type;
56  }
57 }
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
#define CHECK_EQ(x, y)
Definition: Logger.h:198
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
void set_notnull(bool n)
Definition: sqltypes.h:423
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:43
bool is_agg
Definition: TargetInfo.h:40
CHECK(cgen_state)
SQLAgg agg_kind
Definition: TargetInfo.h:41
Definition: sqldefs.h:71
bool is_distinct
Definition: TargetInfo.h:45
bool is_agg_domain_range_equivalent(const SQLAgg &agg_kind)
Definition: TargetInfo.h:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int64_t inline_fixed_encoding_null_val ( const SQLTypeInfo ti)
inline

Definition at line 103 of file SqlTypesLayout.h.

References CHECK(), CHECK_EQ, SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_size(), inline_int_null_val(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_decimal(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_integer(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_time(), kENCODING_DATE_IN_DAYS, kENCODING_DICT, kENCODING_FIXED, and kENCODING_NONE.

103  {
104  if (ti.get_compression() == kENCODING_NONE) {
105  return inline_int_null_val(ti);
106  }
108  switch (ti.get_comp_param()) {
109  case 0:
110  case 32:
111  return inline_int_null_value<int32_t>();
112  case 16:
113  return inline_int_null_value<int16_t>();
114  default:
115 #ifndef __CUDACC__
116  CHECK(false) << "Unknown encoding width for date in days: "
117  << ti.get_comp_param();
118 #else
119  CHECK(false);
120 #endif
121  }
122  }
123  if (ti.get_compression() == kENCODING_DICT) {
124  CHECK(ti.is_string());
125  switch (ti.get_size()) {
126  case 1:
127  return inline_int_null_value<uint8_t>();
128  case 2:
129  return inline_int_null_value<uint16_t>();
130  case 4:
131  return inline_int_null_value<int32_t>();
132  default:
133 #ifndef __CUDACC__
134  CHECK(false) << "Unknown size for dictionary encoded type: " << ti.get_size();
135 #else
136  CHECK(false);
137 #endif
138  }
139  }
141  CHECK(ti.is_integer() || ti.is_time() || ti.is_decimal());
142  CHECK_EQ(0, ti.get_comp_param() % 8);
143  return -(1L << (ti.get_comp_param() - 1));
144 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:335
HOST DEVICE int get_size() const
Definition: sqltypes.h:336
CHECK(cgen_state)
bool is_time() const
Definition: sqltypes.h:483
bool is_integer() const
Definition: sqltypes.h:479
bool is_string() const
Definition: sqltypes.h:477
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
bool is_decimal() const
Definition: sqltypes.h:480

+ Here is the call graph for this function:

double inline_fp_null_val ( const SQLTypeInfo ti)
inline

Definition at line 146 of file SqlTypesLayout.h.

References CHECK(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), inline_fp_null_value< double >(), inline_fp_null_value< float >(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_fp(), kDOUBLE, kFLOAT, and run_benchmark_import::type.

146  {
147  CHECK(ti.is_fp());
148  const auto type = ti.get_type();
149  switch (type) {
150  case kFLOAT:
152  case kDOUBLE:
154  default:
155  abort();
156  }
157 }
bool is_fp() const
Definition: sqltypes.h:481
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
constexpr float inline_fp_null_value< float >()
constexpr double inline_fp_null_value< double >()

+ Here is the call graph for this function:

int64_t inline_int_null_val ( const SQLTypeInfo ti)
inline

Definition at line 71 of file SqlTypesLayout.h.

References CHECK_EQ, SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_logical_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kENCODING_DICT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, and run_benchmark_import::type.

71  {
72  auto type = ti.get_type();
73  if (ti.is_string()) {
75  CHECK_EQ(4, ti.get_logical_size());
76  type = kINT;
77  }
78  switch (type) {
79  case kBOOLEAN:
80  return inline_int_null_value<int8_t>();
81  case kTINYINT:
82  return inline_int_null_value<int8_t>();
83  case kSMALLINT:
84  return inline_int_null_value<int16_t>();
85  case kINT:
86  return inline_int_null_value<int32_t>();
87  case kBIGINT:
88  return inline_int_null_value<int64_t>();
89  case kTIMESTAMP:
90  case kTIME:
91  case kDATE:
92  case kINTERVAL_DAY_TIME:
94  return inline_int_null_value<int64_t>();
95  case kDECIMAL:
96  case kNUMERIC:
97  return inline_int_null_value<int64_t>();
98  default:
99  abort();
100  }
101 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
int get_logical_size() const
Definition: sqltypes.h:337
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
Definition: sqltypes.h:56
bool is_string() const
Definition: sqltypes.h:477
Definition: sqltypes.h:48

+ Here is the call graph for this function:

bool is_unsigned_type ( const SQLTypeInfo ti)
inline

Definition at line 209 of file SqlTypesLayout.h.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_logical_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_size(), and kENCODING_DICT.

Referenced by get_join_column_type_kind().

209  {
210  return ti.get_compression() == kENCODING_DICT && ti.get_size() < ti.get_logical_size();
211 }
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
HOST DEVICE int get_size() const
Definition: sqltypes.h:336
int get_logical_size() const
Definition: sqltypes.h:337

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void set_compact_type ( TargetInfo target,
const SQLTypeInfo new_type 
)
inline

Definition at line 59 of file SqlTypesLayout.h.

References agg_arg(), TargetInfo::agg_arg_type, TargetInfo::agg_kind, TargetInfo::is_agg, kCOUNT, kNULLT, and TargetInfo::sql_type.

Referenced by set_notnull().

59  {
60  if (target.is_agg) {
61  const auto agg_type = target.agg_kind;
62  auto& agg_arg = target.agg_arg_type;
63  if (agg_type != kCOUNT || agg_arg.get_type() != kNULLT) {
64  agg_arg = new_type;
65  return;
66  }
67  }
68  target.sql_type = new_type;
69 }
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:43
bool is_agg
Definition: TargetInfo.h:40
SQLAgg agg_kind
Definition: TargetInfo.h:41
Definition: sqldefs.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function: