OmniSciDB  a5dc49c757
 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 167 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().

167  {
168  uint64_t res = 1;
169  for (unsigned i = 0; i < exp; ++i) {
170  res *= 10;
171  }
172  return res;
173 }

+ Here is the caller graph for this function:

size_t get_bit_width ( const SQLTypeInfo ti)
inline

Definition at line 175 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 anonymous_namespace{TableFunctionExecutionContext.cpp}::append_literal_buffer(), 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().

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

+ 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, TargetInfo::is_agg, is_agg_domain_range_equivalent(), TargetInfo::is_distinct, 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 #ifdef __CUDACC__
45  CHECK((shared::is_any<kCOUNT, kCOUNT_IF, kAPPROX_QUANTILE, kMODE>(agg_type)));
46 #else
47  CHECK((shared::is_any<kCOUNT, kCOUNT_IF, kAPPROX_QUANTILE, kMODE>(agg_type)))
48  << agg_type;
49 #endif
50  CHECK(!target.is_distinct);
51  return target.sql_type;
52  }
53 
54  if (is_agg_domain_range_equivalent(agg_type)) {
55  return agg_arg;
56  } else {
57  // Nullability of the target needs to match that of the agg for proper initialization
58  // of target (aggregate) values
59  auto modified_target_type = target.sql_type;
60  modified_target_type.set_notnull(agg_arg.get_notnull());
61  return modified_target_type;
62  }
63 }
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
bool is_agg_domain_range_equivalent(const SQLAgg agg_kind)
Definition: TargetInfo.h:83
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:53
bool is_agg
Definition: TargetInfo.h:50
SQLAgg agg_kind
Definition: TargetInfo.h:51
void set_notnull(bool n)
Definition: sqltypes.h:477
#define CHECK(condition)
Definition: Logger.h:291
bool is_distinct
Definition: TargetInfo.h:55

+ 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 111 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.

111  {
112  if (ti.get_compression() == kENCODING_NONE) {
113  return inline_int_null_val(ti);
114  }
116  switch (ti.get_comp_param()) {
117  case 0:
118  case 32:
119  return inline_int_null_value<int32_t>();
120  case 16:
121  return inline_int_null_value<int16_t>();
122  default:
123 #ifndef __CUDACC__
124  CHECK(false) << "Unknown encoding width for date in days: "
125  << ti.get_comp_param();
126 #else
127  CHECK(false);
128 #endif
129  }
130  }
131  if (ti.get_compression() == kENCODING_DICT) {
132  CHECK(ti.is_string());
133  switch (ti.get_size()) {
134  case 1:
135  return inline_int_null_value<uint8_t>();
136  case 2:
137  return inline_int_null_value<uint16_t>();
138  case 4:
139  return inline_int_null_value<int32_t>();
140  default:
141 #ifndef __CUDACC__
142  CHECK(false) << "Unknown size for dictionary encoded type: " << ti.get_size();
143 #else
144  CHECK(false);
145 #endif
146  }
147  }
149  CHECK(ti.is_integer() || ti.is_time() || ti.is_decimal());
150  CHECK_EQ(0, ti.get_comp_param() % 8);
151  return -(1LL << (ti.get_comp_param() - 1));
152 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
bool is_time() const
Definition: sqltypes.h:579
bool is_integer() const
Definition: sqltypes.h:567
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
#define CHECK(condition)
Definition: Logger.h:291
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
bool is_string() const
Definition: sqltypes.h:561
bool is_decimal() const
Definition: sqltypes.h:570

+ Here is the call graph for this function:

double inline_fp_null_val ( const SQLTypeInfo ti)
inline

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

154  {
155  CHECK(ti.is_fp());
156  const auto type = ti.get_type();
157  switch (type) {
158  case kFLOAT:
160  case kDOUBLE:
162  default:
163  abort();
164  }
165 }
bool is_fp() const
Definition: sqltypes.h:573
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
constexpr float inline_fp_null_value< float >()
constexpr double inline_fp_null_value< double >()
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

int64_t inline_int_null_val ( const SQLTypeInfo ti)
inline

Definition at line 79 of file SqlTypesLayout.h.

References CHECK_EQ, SQLTypeInfo::get_compression(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_type(), SQLTypeInfo::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.

79  {
80  auto type = ti.get_type();
81  if (ti.is_string()) {
83  CHECK_EQ(4, ti.get_logical_size());
84  type = kINT;
85  }
86  switch (type) {
87  case kBOOLEAN:
88  return inline_int_null_value<int8_t>();
89  case kTINYINT:
90  return inline_int_null_value<int8_t>();
91  case kSMALLINT:
92  return inline_int_null_value<int16_t>();
93  case kINT:
94  return inline_int_null_value<int32_t>();
95  case kBIGINT:
96  return inline_int_null_value<int64_t>();
97  case kTIMESTAMP:
98  case kTIME:
99  case kDATE:
100  case kINTERVAL_DAY_TIME:
102  return inline_int_null_value<int64_t>();
103  case kDECIMAL:
104  case kNUMERIC:
105  return inline_int_null_value<int64_t>();
106  default:
107  abort();
108  }
109 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
Definition: sqltypes.h:76
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
int get_logical_size() const
Definition: sqltypes.h:421
Definition: sqltypes.h:80
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
Definition: sqltypes.h:72
bool is_string() const
Definition: sqltypes.h:561

+ Here is the call graph for this function:

bool is_unsigned_type ( const SQLTypeInfo ti)
inline

Definition at line 232 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().

232  {
233  return ti.get_compression() == kENCODING_DICT && ti.get_size() < ti.get_logical_size();
234 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
int get_logical_size() const
Definition: sqltypes.h:421
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399

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

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

Referenced by set_notnull().

65  {
66  if (target.is_agg) {
67  const auto agg_type = target.agg_kind;
68  auto& agg_arg = target.agg_arg_type;
69  if (!shared::is_any<kCOUNT, kCOUNT_IF>(agg_type) || agg_arg.get_type() != kNULLT) {
70  agg_arg = new_type;
71  return;
72  }
73  }
74  target.sql_type = new_type;
75 }
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: