OmniSciDB  8a228a1076
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)
 

Detailed Description

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

Definition in file SqlTypesLayout.h.

Function Documentation

◆ exp_to_scale()

uint64_t exp_to_scale ( const unsigned  exp)
inline

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

160  {
161  uint64_t res = 1;
162  for (unsigned i = 0; i < exp; ++i) {
163  res *= 10;
164  }
165  return res;
166 }
+ Here is the caller graph for this function:

◆ get_bit_width()

size_t get_bit_width ( const SQLTypeInfo ti)
inline

Definition at line 168 of file SqlTypesLayout.h.

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

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

168  {
169  const auto int_type = ti.is_decimal() ? kBIGINT : ti.get_type();
170  switch (int_type) {
171  case kNULLT:
172  LOG(FATAL) << "Untyped NULL values are not supported. Please CAST any NULL "
173  "constants to a type.";
174  case kBOOLEAN:
175  return 8;
176  case kTINYINT:
177  return 8;
178  case kSMALLINT:
179  return 16;
180  case kINT:
181  return 32;
182  case kBIGINT:
183  return 64;
184  case kFLOAT:
185  return 32;
186  case kDOUBLE:
187  return 64;
188  case kTIME:
189  case kTIMESTAMP:
190  case kDATE:
191  case kINTERVAL_DAY_TIME:
193  return sizeof(time_t) * 8;
194  case kTEXT:
195  case kVARCHAR:
196  case kCHAR:
197  return 32;
198  case kARRAY:
199  if (ti.get_size() == -1) {
200  throw std::runtime_error("Projecting on unsized array column not supported.");
201  }
202  return ti.get_size() * 8;
203  case kPOINT:
204  case kLINESTRING:
205  case kPOLYGON:
206  case kMULTIPOLYGON:
207  return 32;
208  case kCOLUMN:
209  return ti.get_elem_type().get_size() * 8;
210  default:
211  LOG(FATAL) << "Unhandled int_type: " << int_type;
212  return {};
213  }
214 }
Definition: sqltypes.h:51
#define LOG(tag)
Definition: Logger.h:188
HOST DEVICE int get_size() const
Definition: sqltypes.h:269
bool is_decimal() const
Definition: sqltypes.h:419
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:623
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_compact_type()

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, SQLTypeInfo::get_elem_type(), TargetInfo::is_agg, is_agg_domain_range_equivalent(), SQLTypeInfo::is_column(), TargetInfo::is_distinct, kCOUNT, kNULLT, SQLTypeInfo::set_notnull(), and TargetInfo::sql_type.

Referenced by anonymous_namespace{TargetExprBuilder.cpp}::agg_fn_base_names(), 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(), get_col_byte_widths(), GroupByAndAggregate::getKeylessInfo(), 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.is_column() ? target.sql_type.get_elem_type()
39  : 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:205
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:43
bool is_agg
Definition: TargetInfo.h:40
bool is_column() const
Definition: sqltypes.h:429
SQLAgg agg_kind
Definition: TargetInfo.h:41
Definition: sqldefs.h:76
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:623
void set_notnull(bool n)
Definition: sqltypes.h:356
#define CHECK(condition)
Definition: Logger.h:197
bool is_distinct
Definition: TargetInfo.h:45
bool is_agg_domain_range_equivalent(const SQLAgg &agg_kind)
Definition: TargetInfo.h:64
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inline_fixed_encoding_null_val()

int64_t inline_fixed_encoding_null_val ( const SQLTypeInfo ti)
inline

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

104  {
105  if (ti.get_compression() == kENCODING_NONE) {
106  return inline_int_null_val(ti);
107  }
109  switch (ti.get_comp_param()) {
110  case 0:
111  case 32:
112  return inline_int_null_value<int32_t>();
113  case 16:
114  return inline_int_null_value<int16_t>();
115  default:
116 #ifndef __CUDACC__
117  CHECK(false) << "Unknown encoding width for date in days: "
118  << ti.get_comp_param();
119 #else
120  CHECK(false);
121 #endif
122  }
123  }
124  if (ti.get_compression() == kENCODING_DICT) {
125  CHECK(ti.is_string());
126  switch (ti.get_size()) {
127  case 1:
128  return inline_int_null_value<uint8_t>();
129  case 2:
130  return inline_int_null_value<uint16_t>();
131  case 4:
132  return inline_int_null_value<int32_t>();
133  default:
134 #ifndef __CUDACC__
135  CHECK(false) << "Unknown size for dictionary encoded type: " << ti.get_size();
136 #else
137  CHECK(false);
138 #endif
139  }
140  }
142  CHECK(ti.is_integer() || ti.is_time() || ti.is_decimal());
143  CHECK_EQ(0, ti.get_comp_param() % 8);
144  return -(1L << (ti.get_comp_param() - 1));
145 }
int64_t inline_int_null_val(const SQLTypeInfo &ti)
#define CHECK_EQ(x, y)
Definition: Logger.h:205
bool is_time() const
Definition: sqltypes.h:422
bool is_string() const
Definition: sqltypes.h:416
bool is_integer() const
Definition: sqltypes.h:418
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE int get_size() const
Definition: sqltypes.h:269
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
bool is_decimal() const
Definition: sqltypes.h:419
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:

◆ inline_fp_null_val()

double inline_fp_null_val ( const SQLTypeInfo ti)
inline

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

147  {
148  CHECK(ti.is_fp());
149  const auto type = ti.get_type();
150  switch (type) {
151  case kFLOAT:
153  case kDOUBLE:
155  default:
156  abort();
157  }
158 }
constexpr float inline_fp_null_value< float >()
constexpr double inline_fp_null_value< double >()
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
bool is_fp() const
Definition: sqltypes.h:420
+ Here is the call graph for this function:

◆ inline_int_null_val()

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(), 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.

Referenced by inline_fixed_encoding_null_val().

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  case kDATE:
93  case kINTERVAL_DAY_TIME:
95  return inline_int_null_value<int64_t>();
96  case kDECIMAL:
97  case kNUMERIC:
98  return inline_int_null_value<int64_t>();
99  default:
100  abort();
101  }
102 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
bool is_string() const
Definition: sqltypes.h:416
Definition: sqltypes.h:51
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
int get_logical_size() const
Definition: sqltypes.h:270
Definition: sqltypes.h:55
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_unsigned_type()

bool is_unsigned_type ( const SQLTypeInfo ti)
inline

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

216  {
217  return ti.get_compression() == kENCODING_DICT && ti.get_size() < ti.get_logical_size();
218 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:269
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
int get_logical_size() const
Definition: sqltypes.h:270
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_compact_type()

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: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:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function: