OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlTypesLayout.h File Reference
#include "Shared/TargetInfo.h"
#include "Logger/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)
 

Function Documentation

uint64_t exp_to_scale ( const unsigned  exp)
inline

Definition at line 163 of file SqlTypesLayout.h.

References run_benchmark_import::res.

Referenced by Executor::castToFP(), CodeGenerator::codegenCastBetweenIntTypes(), 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().

163  {
164  uint64_t res = 1;
165  for (unsigned i = 0; i < exp; ++i) {
166  res *= 10;
167  }
168  return res;
169 }

+ Here is the caller graph for this function:

size_t get_bit_width ( const SQLTypeInfo ti)
inline

Definition at line 171 of file SqlTypesLayout.h.

References SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), SQLTypeInfo::is_decimal(), kARRAY, kBIGINT, kBOOLEAN, kCHAR, kCOLUMN, kCOLUMN_LIST, kDATE, kDOUBLE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kNULLT, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, and UNREACHABLE.

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(), anonymous_namespace{QueryMemoryDescriptor.cpp}::get_col_byte_widths(), anonymous_namespace{QueryMemoryDescriptor.cpp}::is_int_and_no_bigger_than(), and result_set::lazy_decode().

171  {
172  const auto int_type = ti.is_decimal() ? kBIGINT : ti.get_type();
173  switch (int_type) {
174  case kNULLT:
175  throw std::runtime_error(
176  "Untyped NULL values are not supported. Please CAST any NULL "
177  "constants to a type.");
178  case kBOOLEAN:
179  return 8;
180  case kTINYINT:
181  return 8;
182  case kSMALLINT:
183  return 16;
184  case kINT:
185  return 32;
186  case kBIGINT:
187  return 64;
188  case kFLOAT:
189  return 32;
190  case kDOUBLE:
191  return 64;
192  case kTIME:
193  case kTIMESTAMP:
194  case kDATE:
195  case kINTERVAL_DAY_TIME:
197  return sizeof(time_t) * 8;
198  case kTEXT:
199  case kVARCHAR:
200  case kCHAR:
201  return 32;
202  case kARRAY:
203  if (ti.get_size() == -1) {
204  throw std::runtime_error("Projecting on unsized array column not supported.");
205  }
206  return ti.get_size() * 8;
207  case kPOINT:
208  case kMULTIPOINT:
209  case kLINESTRING:
210  case kMULTILINESTRING:
211  case kPOLYGON:
212  case kMULTIPOLYGON:
213  return 32;
214  case kCOLUMN:
215  case kCOLUMN_LIST:
216  return ti.get_elem_type().get_size() * 8;
217  default:
218  break;
219  }
220 #ifdef __CUDACC__
221  UNREACHABLE();
222 #else
223  UNREACHABLE() << "Unhandled int_type: " << int_type;
224 #endif
225  return {};
226 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:389
Definition: sqltypes.h:64
#define UNREACHABLE()
Definition: Logger.h:266
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
Definition: sqltypes.h:67
Definition: sqltypes.h:68
Definition: sqltypes.h:56
Definition: sqltypes.h:60
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:956
bool is_decimal() const
Definition: sqltypes.h:578

+ 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 37 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, SQLTypeInfo::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(), anonymous_namespace{GpuSharedMemoryUtils.cpp}::codegen_smem_dest_slot_ptr(), TargetExprCodegen::codegenAggregate(), ColSlotContext::ColSlotContext(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_value(), anonymous_namespace{QueryMemoryDescriptor.cpp}::get_col_byte_widths(), anonymous_namespace{GroupByAndAggregate.cpp}::get_keyless_info(), init_agg_val_vec(), ResultSet::makeTargetValue(), ResultSet::ResultSetComparator< BUFFER_ITERATOR_TYPE >::operator()(), ResultSetStorage::reduceSingleRow(), and set_notnull().

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

+ 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 107 of file SqlTypesLayout.h.

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

107  {
108  if (ti.get_compression() == kENCODING_NONE) {
109  return inline_int_null_val(ti);
110  }
112  switch (ti.get_comp_param()) {
113  case 0:
114  case 32:
115  return inline_int_null_value<int32_t>();
116  case 16:
117  return inline_int_null_value<int16_t>();
118  default:
119 #ifndef __CUDACC__
120  CHECK(false) << "Unknown encoding width for date in days: "
121  << ti.get_comp_param();
122 #else
123  CHECK(false);
124 #endif
125  }
126  }
127  if (ti.get_compression() == kENCODING_DICT) {
128  CHECK(ti.is_string());
129  switch (ti.get_size()) {
130  case 1:
131  return inline_int_null_value<uint8_t>();
132  case 2:
133  return inline_int_null_value<uint16_t>();
134  case 4:
135  return inline_int_null_value<int32_t>();
136  default:
137 #ifndef __CUDACC__
138  CHECK(false) << "Unknown size for dictionary encoded type: " << ti.get_size();
139 #else
140  CHECK(false);
141 #endif
142  }
143  }
145  CHECK(ti.is_integer() || ti.is_time() || ti.is_decimal());
146  CHECK_EQ(0, ti.get_comp_param() % 8);
147  return -(1LL << (ti.get_comp_param() - 1));
148 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
HOST DEVICE int get_size() const
Definition: sqltypes.h:389
bool is_time() const
Definition: sqltypes.h:581
bool is_integer() const
Definition: sqltypes.h:577
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:387
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:388
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
bool is_string() const
Definition: sqltypes.h:575
bool is_decimal() const
Definition: sqltypes.h:578

+ Here is the call graph for this function:

double inline_fp_null_val ( const SQLTypeInfo ti)
inline

Definition at line 150 of file SqlTypesLayout.h.

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

150  {
151  CHECK(ti.is_fp());
152  const auto type = ti.get_type();
153  switch (type) {
154  case kFLOAT:
156  case kDOUBLE:
158  default:
159  abort();
160  }
161 }
bool is_fp() const
Definition: sqltypes.h:579
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
constexpr float inline_fp_null_value< float >()
constexpr double inline_fp_null_value< double >()
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

int64_t inline_int_null_val ( const SQLTypeInfo ti)
inline

Definition at line 72 of file SqlTypesLayout.h.

References CHECK_EQ, SQLTypeInfo::get_compression(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_type(), inline_fixed_encoding_null_val(), SQLTypeInfo::is_string(), kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kENCODING_DICT, kENCODING_FIXED, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, and run_benchmark_import::type.

72  {
73  auto type = ti.get_type();
74  if (ti.is_string()) {
76  CHECK_EQ(4, ti.get_logical_size());
77  type = kINT;
78  }
79  switch (type) {
80  case kBOOLEAN:
81  return inline_int_null_value<int8_t>();
82  case kTINYINT:
83  return inline_int_null_value<int8_t>();
84  case kSMALLINT:
85  return inline_int_null_value<int16_t>();
86  case kINT:
87  return inline_int_null_value<int32_t>();
88  case kBIGINT:
89  return inline_int_null_value<int64_t>();
90  case kTIMESTAMP:
91  case kTIME:
92  if (ti.get_compression() == kENCODING_FIXED) {
94  }
95  case kDATE:
96  case kINTERVAL_DAY_TIME:
98  return inline_int_null_value<int64_t>();
99  case kDECIMAL:
100  case kNUMERIC:
101  return inline_int_null_value<int64_t>();
102  default:
103  abort();
104  }
105 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
Definition: sqltypes.h:64
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
int get_logical_size() const
Definition: sqltypes.h:399
Definition: sqltypes.h:68
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:387
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:60
bool is_string() const
Definition: sqltypes.h:575

+ Here is the call graph for this function:

bool is_unsigned_type ( const SQLTypeInfo ti)
inline

Definition at line 228 of file SqlTypesLayout.h.

References SQLTypeInfo::get_compression(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_size(), and kENCODING_DICT.

Referenced by get_join_column_type_kind().

228  {
229  return ti.get_compression() == kENCODING_DICT && ti.get_size() < ti.get_logical_size();
230 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:389
int get_logical_size() const
Definition: sqltypes.h:399
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:387

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

60  {
61  if (target.is_agg) {
62  const auto agg_type = target.agg_kind;
63  auto& agg_arg = target.agg_arg_type;
64  if (agg_type != kCOUNT || agg_arg.get_type() != kNULLT) {
65  agg_arg = new_type;
66  return;
67  }
68  }
69  target.sql_type = new_type;
70 }
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:53
bool is_agg
Definition: TargetInfo.h:50
SQLAgg agg_kind
Definition: TargetInfo.h:51
Definition: sqldefs.h:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function: