OmniSciDB  0264ff685a
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 726 of file Analyzer.cpp.

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

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

726  {
727  if (ti.get_scale() > 18) {
728  auto truncated_ti = ti;
729  truncated_ti.set_scale(18);
730  auto truncated_dec = dec;
731  for (int i = 0; i < ti.get_scale() - 18; ++i) {
732  truncated_dec /= 10;
733  }
734  return decimal_to_int_frac(truncated_dec, truncated_ti);
735  }
736  int64_t integral_part = dec;
737  int64_t scale = 1;
738  for (int i = 0; i < ti.get_scale(); i++) {
739  integral_part /= 10;
740  scale *= 10;
741  }
742  return {integral_part, dec - integral_part * scale, scale};
743 }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:316
void set_scale(int s)
Definition: sqltypes.h:406
IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:726
+ 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 1388 of file Analyzer.cpp.

References omnisci.dtypes::T.

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

◆ is_expr_nullable()

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

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

1505  {
1506  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1507  if (const_expr) {
1508  return const_expr->get_is_null();
1509  }
1510  const auto& expr_ti = expr->get_type_info();
1511  return !expr_ti.get_notnull();
1512 }
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:318
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 1514 of file Analyzer.cpp.

References is_expr_nullable().

1515  {
1516  if (is_expr_nullable(a.get())) {
1517  return true;
1518  }
1519  for (const auto& v : l) {
1520  if (is_expr_nullable(v.get())) {
1521  return true;
1522  }
1523  }
1524  return false;
1525 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1505
+ 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 1086 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().

1086  {
1087  switch (ti.get_type()) {
1088  case kBOOLEAN:
1089  return constval.tinyintval == NULL_BOOLEAN;
1090  case kTINYINT:
1091  return constval.tinyintval == NULL_TINYINT;
1092  case kINT:
1093  return constval.intval == NULL_INT;
1094  case kSMALLINT:
1095  return constval.smallintval == NULL_SMALLINT;
1096  case kBIGINT:
1097  case kNUMERIC:
1098  case kDECIMAL:
1099  return constval.bigintval == NULL_BIGINT;
1100  case kTIME:
1101  case kTIMESTAMP:
1102  case kDATE:
1103  return constval.bigintval == NULL_BIGINT;
1104  case kVARCHAR:
1105  case kCHAR:
1106  case kTEXT:
1107  return constval.stringval == nullptr;
1108  case kPOINT:
1109  case kLINESTRING:
1110  case kPOLYGON:
1111  case kMULTIPOLYGON:
1112  return constval.stringval == nullptr;
1113  case kFLOAT:
1114  return constval.floatval == NULL_FLOAT;
1115  case kDOUBLE:
1116  return constval.doubleval == NULL_DOUBLE;
1117  case kNULLT:
1118  return constval.bigintval == 0;
1119  case kARRAY:
1120  return constval.arrayval == nullptr;
1121  default:
1122  UNREACHABLE();
1123  }
1124  UNREACHABLE();
1125  return false;
1126 }
int8_t tinyintval
Definition: sqltypes.h:203
#define NULL_DOUBLE
Definition: sqltypes.h:48
#define NULL_FLOAT
#define NULL_BIGINT
VarlenDatum * arrayval
Definition: sqltypes.h:209
#define UNREACHABLE()
Definition: Logger.h:241
int32_t intval
Definition: sqltypes.h:205
#define NULL_INT
float floatval
Definition: sqltypes.h:207
int64_t bigintval
Definition: sqltypes.h:206
int16_t smallintval
Definition: sqltypes.h:204
#define NULL_BOOLEAN
std::string * stringval
Definition: sqltypes.h:211
Definition: sqltypes.h:51
Definition: sqltypes.h:52
Definition: sqltypes.h:40
#define NULL_TINYINT
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
#define NULL_SMALLINT
Definition: sqltypes.h:44
double doubleval
Definition: sqltypes.h:208
+ 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 746 of file Analyzer.cpp.

References omnisci.dtypes::T.

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