OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::anonymous_namespace{Analyzer.cpp} Namespace Reference

Functions

template<typename T >
floatFromDecimal (int64_t const dec, unsigned const scale)
 
template<typename FLOAT_TYPE , typename INT_TYPE >
constexpr FLOAT_TYPE maxRound ()
 
template<typename TO , typename FROM >
TO safeNarrow (FROM const from)
 
template<typename T >
roundDecimal (int64_t n, unsigned scale)
 
template<typename TO , typename FROM >
TO safeRound (FROM const from)
 
template<typename T >
int64_t safeScale (T from, unsigned const scale)
 
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)
 
SQLTypes get_ti_from_geo (const Geospatial::GeoBase *geo)
 

Function Documentation

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

Definition at line 1453 of file Analyzer.cpp.

References omnisci.dtypes::T.

1453  {
1454  return std::dynamic_pointer_cast<T>(expr) != nullptr;
1455 }
template<typename T >
T Analyzer::anonymous_namespace{Analyzer.cpp}::floatFromDecimal ( int64_t const  dec,
unsigned const  scale 
)

Definition at line 737 of file Analyzer.cpp.

References shared::power10(), and omnisci.dtypes::T.

737  {
738  static_assert(std::is_floating_point_v<T>);
739  return static_cast<T>(dec) / shared::power10(scale);
740 }
double power10(unsigned const x)
Definition: misc.h:262

+ Here is the call graph for this function:

SQLTypes Analyzer::anonymous_namespace{Analyzer.cpp}::get_ti_from_geo ( const Geospatial::GeoBase geo)

Definition at line 3458 of file Analyzer.cpp.

References CHECK, Geospatial::GeoBase::getType(), Geospatial::GeoBase::kLINESTRING, kLINESTRING, Geospatial::GeoBase::kMULTIPOLYGON, kMULTIPOLYGON, kNULLT, Geospatial::GeoBase::kPOINT, kPOINT, Geospatial::GeoBase::kPOLYGON, kPOLYGON, and UNREACHABLE.

Referenced by Analyzer::GeoConstant::GeoConstant(), and RelAlgTranslator::translateGeoFunctionArg().

3458  {
3459  CHECK(geo);
3460  switch (geo->getType()) {
3462  return kPOINT;
3463  }
3465  return kLINESTRING;
3466  }
3468  return kPOLYGON;
3469  }
3471  return kMULTIPOLYGON;
3472  }
3473  default:
3474  UNREACHABLE();
3475  return kNULLT;
3476  }
3477 }
#define UNREACHABLE()
Definition: Logger.h:253
#define CHECK(condition)
Definition: Logger.h:209
virtual GeoType getType() const =0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

1570  {
1571  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1572  if (const_expr) {
1573  return const_expr->get_is_null();
1574  }
1575  const auto& expr_ti = expr->get_type_info();
1576  return !expr_ti.get_notnull();
1577 }
bool get_is_null() const
Definition: Analyzer.h:333
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 1579 of file Analyzer.cpp.

References is_expr_nullable().

1580  {
1581  if (is_expr_nullable(a.get())) {
1582  return true;
1583  }
1584  for (const auto& v : l) {
1585  if (is_expr_nullable(v.get())) {
1586  return true;
1587  }
1588  }
1589  return false;
1590 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1570
constexpr double a
Definition: Utm.h:38

+ Here is the call graph for this function:

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

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

1150  {
1151  switch (ti.get_type()) {
1152  case kBOOLEAN:
1153  return constval.tinyintval == NULL_BOOLEAN;
1154  case kTINYINT:
1155  return constval.tinyintval == NULL_TINYINT;
1156  case kINT:
1157  return constval.intval == NULL_INT;
1158  case kSMALLINT:
1159  return constval.smallintval == NULL_SMALLINT;
1160  case kBIGINT:
1161  case kNUMERIC:
1162  case kDECIMAL:
1163  return constval.bigintval == NULL_BIGINT;
1164  case kTIME:
1165  case kTIMESTAMP:
1166  case kDATE:
1167  return constval.bigintval == NULL_BIGINT;
1168  case kVARCHAR:
1169  case kCHAR:
1170  case kTEXT:
1171  return constval.stringval == nullptr;
1172  case kPOINT:
1173  case kLINESTRING:
1174  case kPOLYGON:
1175  case kMULTIPOLYGON:
1176  return constval.stringval == nullptr;
1177  case kFLOAT:
1178  return constval.floatval == NULL_FLOAT;
1179  case kDOUBLE:
1180  return constval.doubleval == NULL_DOUBLE;
1181  case kNULLT:
1182  return constval.bigintval == 0;
1183  case kARRAY:
1184  return constval.arrayval == nullptr;
1185  default:
1186  UNREACHABLE();
1187  }
1188  UNREACHABLE();
1189  return false;
1190 }
int8_t tinyintval
Definition: sqltypes.h:212
#define NULL_DOUBLE
Definition: sqltypes.h:49
#define NULL_FLOAT
#define NULL_BIGINT
VarlenDatum * arrayval
Definition: sqltypes.h:218
#define UNREACHABLE()
Definition: Logger.h:253
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
int32_t intval
Definition: sqltypes.h:214
#define NULL_INT
float floatval
Definition: sqltypes.h:216
int64_t bigintval
Definition: sqltypes.h:215
int16_t smallintval
Definition: sqltypes.h:213
#define NULL_BOOLEAN
std::string * stringval
Definition: sqltypes.h:220
Definition: sqltypes.h:52
Definition: sqltypes.h:53
Definition: sqltypes.h:41
#define NULL_TINYINT
#define NULL_SMALLINT
Definition: sqltypes.h:45
double doubleval
Definition: sqltypes.h:217

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename FLOAT_TYPE , typename INT_TYPE >
constexpr FLOAT_TYPE Analyzer::anonymous_namespace{Analyzer.cpp}::maxRound ( )

Definition at line 749 of file Analyzer.cpp.

749  {
750  static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
751  constexpr int dd =
752  std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
753  if constexpr (0 < dd) { // NOLINT
754  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
755  } else {
756  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max());
757  }
758 }
template<typename T >
T Analyzer::anonymous_namespace{Analyzer.cpp}::roundDecimal ( int64_t  n,
unsigned  scale 
)

Definition at line 772 of file Analyzer.cpp.

References anonymous_namespace{Utm.h}::n, and omnisci.dtypes::T.

772  {
773  static_assert(std::is_integral_v<T>);
774  constexpr size_t max_scale = std::numeric_limits<uint64_t>::digits10; // 19
775  constexpr auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
776  if (scale == 0) {
777  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
778  return safeNarrow<T>(n);
779  } else {
780  return n;
781  }
782  } else if (max_scale < scale) {
783  return 0; // 0.09223372036854775807 rounds to 0
784  }
785  uint64_t const u = std::abs(n);
786  uint64_t const pow = pow10[scale];
787  uint64_t div = u / pow;
788  uint64_t rem = u % pow;
789  div += pow / 2 <= rem;
790  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
791  return safeNarrow<T>(static_cast<int64_t>(n < 0 ? -div : div));
792  } else {
793  return n < 0 ? -div : div;
794  }
795 }
constexpr double n
Definition: Utm.h:46
template<typename TO , typename FROM >
TO Analyzer::anonymous_namespace{Analyzer.cpp}::safeNarrow ( FROM const  from)

Definition at line 761 of file Analyzer.cpp.

References FROM, and TO.

761  {
762  static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
763  static_assert(sizeof(TO) < sizeof(FROM));
764  if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
765  static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
766  throw std::runtime_error("Overflow or underflow");
767  }
768  return static_cast<TO>(from);
769 }
#define TO
#define FROM
template<typename TO , typename FROM >
TO Analyzer::anonymous_namespace{Analyzer.cpp}::safeRound ( FROM const  from)

Definition at line 798 of file Analyzer.cpp.

References FROM, anonymous_namespace{Utm.h}::n, and TO.

798  {
799  static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
800  constexpr FROM max_float = maxRound<FROM, TO>();
801  FROM const n = std::round(from);
802  if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
803  throw std::runtime_error("Overflow or underflow");
804  }
805  return static_cast<TO>(n);
806 }
#define TO
#define FROM
constexpr double n
Definition: Utm.h:46
template<typename T >
int64_t Analyzer::anonymous_namespace{Analyzer.cpp}::safeScale ( from,
unsigned const  scale 
)

Definition at line 810 of file Analyzer.cpp.

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

810  {
811  static_assert(std::is_arithmetic_v<T>);
812  constexpr size_t max_scale = std::numeric_limits<int64_t>::digits10; // 18
813  constexpr auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
814  if constexpr (std::is_integral_v<T>) { // NOLINT
815  int64_t retval;
816  if (scale < pow10.size()) {
817 #ifdef __linux__
818  if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
819  return retval;
820  }
821  // Not over flow safe.
822 #else
823  return from * pow10[scale];
824 #endif
825  }
826  } else if constexpr (std::is_floating_point_v<T>) {
827  if (scale < pow10.size()) {
828  return safeRound<int64_t>(from * pow10[scale]);
829  }
830  }
831  if (from == 0) {
832  return 0;
833  }
834  throw std::runtime_error("Overflow or underflow");
835 }

+ Here is the caller graph for this function: