OmniSciDB  f632821e96
Analyzer::anonymous_namespace{Analyzer.cpp} Namespace Reference

Classes

struct  IntFracRepr
 

Functions

IntFracRepr decimal_to_int_frac (const int64_t dec, const SQLTypeInfo &ti)
 
template<class T >
safe_narrow (const int64_t v)
 
bool is_null_value (const SQLTypeInfo &ti, const Datum &constval)
 
template<class T >
bool expr_is (const std::shared_ptr< Analyzer::Expr > &expr)
 
bool is_expr_nullable (const Analyzer::Expr *expr)
 
bool is_in_values_nullable (const std::shared_ptr< Analyzer::Expr > &a, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
 

Function Documentation

◆ decimal_to_int_frac()

IntFracRepr Analyzer::anonymous_namespace{Analyzer.cpp}::decimal_to_int_frac ( const int64_t  dec,
const SQLTypeInfo ti 
)

Definition at line 728 of file Analyzer.cpp.

References SQLTypeInfo::get_scale(), and SQLTypeInfo::set_scale().

Referenced by Analyzer::Constant::cast_number().

728  {
729  if (ti.get_scale() > 18) {
730  auto truncated_ti = ti;
731  truncated_ti.set_scale(18);
732  auto truncated_dec = dec;
733  for (int i = 0; i < ti.get_scale() - 18; ++i) {
734  truncated_dec /= 10;
735  }
736  return decimal_to_int_frac(truncated_dec, truncated_ti);
737  }
738  int64_t integral_part = dec;
739  int64_t scale = 1;
740  for (int i = 0; i < ti.get_scale(); i++) {
741  integral_part /= 10;
742  scale *= 10;
743  }
744  return {integral_part, dec - integral_part * scale, scale};
745 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:264
void set_scale(int s)
Definition: sqltypes.h:354
IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:728
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expr_is()

template<class T >
bool Analyzer::anonymous_namespace{Analyzer.cpp}::expr_is ( const std::shared_ptr< Analyzer::Expr > &  expr)

Definition at line 1390 of file Analyzer.cpp.

1390  {
1391  return std::dynamic_pointer_cast<T>(expr) != nullptr;
1392 }

◆ is_expr_nullable()

bool Analyzer::anonymous_namespace{Analyzer.cpp}::is_expr_nullable ( const Analyzer::Expr expr)

Definition at line 1507 of file Analyzer.cpp.

References Analyzer::Constant::get_is_null(), SQLTypeInfo::get_notnull(), and Analyzer::Expr::get_type_info().

Referenced by is_in_values_nullable().

1507  {
1508  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1509  if (const_expr) {
1510  return const_expr->get_is_null();
1511  }
1512  const auto& expr_ti = expr->get_type_info();
1513  return !expr_ti.get_notnull();
1514 }
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:266
bool get_is_null() const
Definition: Analyzer.h:334
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_in_values_nullable()

bool Analyzer::anonymous_namespace{Analyzer.cpp}::is_in_values_nullable ( const std::shared_ptr< Analyzer::Expr > &  a,
const std::list< std::shared_ptr< Analyzer::Expr >> &  l 
)

Definition at line 1516 of file Analyzer.cpp.

References is_expr_nullable().

1517  {
1518  if (is_expr_nullable(a.get())) {
1519  return true;
1520  }
1521  for (const auto& v : l) {
1522  if (is_expr_nullable(v.get())) {
1523  return true;
1524  }
1525  }
1526  return false;
1527 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1507
+ Here is the call graph for this function:

◆ is_null_value()

bool Analyzer::anonymous_namespace{Analyzer.cpp}::is_null_value ( const SQLTypeInfo ti,
const Datum constval 
)
inline

Definition at line 1088 of file Analyzer.cpp.

References Datum::arrayval, Datum::bigintval, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_type(), Datum::intval, kARRAY, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kNULLT, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, NULL_BIGINT, NULL_BOOLEAN, NULL_DOUBLE, NULL_FLOAT, NULL_INT, NULL_SMALLINT, NULL_TINYINT, Datum::smallintval, Datum::stringval, Datum::tinyintval, and UNREACHABLE.

Referenced by Analyzer::Constant::do_cast().

1088  {
1089  switch (ti.get_type()) {
1090  case kBOOLEAN:
1091  return constval.tinyintval == NULL_BOOLEAN;
1092  case kTINYINT:
1093  return constval.tinyintval == NULL_TINYINT;
1094  case kINT:
1095  return constval.intval == NULL_INT;
1096  case kSMALLINT:
1097  return constval.smallintval == NULL_SMALLINT;
1098  case kBIGINT:
1099  case kNUMERIC:
1100  case kDECIMAL:
1101  return constval.bigintval == NULL_BIGINT;
1102  case kTIME:
1103  case kTIMESTAMP:
1104  case kDATE:
1105  return constval.bigintval == NULL_BIGINT;
1106  case kVARCHAR:
1107  case kCHAR:
1108  case kTEXT:
1109  return constval.stringval == nullptr;
1110  case kPOINT:
1111  case kLINESTRING:
1112  case kPOLYGON:
1113  case kMULTIPOLYGON:
1114  return constval.stringval == nullptr;
1115  case kFLOAT:
1116  return constval.floatval == NULL_FLOAT;
1117  case kDOUBLE:
1118  return constval.doubleval == NULL_DOUBLE;
1119  case kNULLT:
1120  return constval.bigintval == 0;
1121  case kARRAY:
1122  return constval.arrayval == nullptr;
1123  default:
1124  UNREACHABLE();
1125  }
1126  UNREACHABLE();
1127  return false;
1128 }
int8_t tinyintval
Definition: sqltypes.h:135
#define NULL_DOUBLE
Definition: sqltypes.h:186
Definition: sqltypes.h:51
#define NULL_BIGINT
Definition: sqltypes.h:184
VarlenDatum * arrayval
Definition: sqltypes.h:141
#define UNREACHABLE()
Definition: Logger.h:241
int32_t intval
Definition: sqltypes.h:137
float floatval
Definition: sqltypes.h:139
#define NULL_TINYINT
Definition: sqltypes.h:181
int64_t bigintval
Definition: sqltypes.h:138
#define NULL_FLOAT
Definition: sqltypes.h:185
int16_t smallintval
Definition: sqltypes.h:136
#define NULL_INT
Definition: sqltypes.h:183
std::string * stringval
Definition: sqltypes.h:143
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
#define NULL_SMALLINT
Definition: sqltypes.h:182
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqltypes.h:47
#define NULL_BOOLEAN
Definition: sqltypes.h:180
double doubleval
Definition: sqltypes.h:140
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ safe_narrow()

template<class T >
T Analyzer::anonymous_namespace{Analyzer.cpp}::safe_narrow ( const int64_t  v)

Definition at line 748 of file Analyzer.cpp.

748  {
749  if (v > std::numeric_limits<T>::max() || v < std::numeric_limits<T>::min()) {
750  throw std::runtime_error("Overflow or underflow");
751  }
752  return static_cast<T>(v);
753 }