OmniSciDB  085a039ca4
 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 1459 of file Analyzer.cpp.

References heavydb.dtypes::T.

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

Definition at line 743 of file Analyzer.cpp.

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

743  {
744  static_assert(std::is_floating_point_v<T>);
745  return static_cast<T>(dec) / shared::power10(scale);
746 }
double power10(unsigned const x)
Definition: misc.h:270

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

3621  {
3622  CHECK(geo);
3623  switch (geo->getType()) {
3625  return kPOINT;
3626  }
3628  return kLINESTRING;
3629  }
3631  return kPOLYGON;
3632  }
3634  return kMULTIPOLYGON;
3635  }
3636  default:
3637  UNREACHABLE();
3638  return kNULLT;
3639  }
3640 }
#define UNREACHABLE()
Definition: Logger.h:267
#define CHECK(condition)
Definition: Logger.h:223
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 1576 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().

1576  {
1577  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1578  if (const_expr) {
1579  return const_expr->get_is_null();
1580  }
1581  const auto& expr_ti = expr->get_type_info();
1582  return !expr_ti.get_notnull();
1583 }
bool get_is_null() const
Definition: Analyzer.h:341
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
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 1585 of file Analyzer.cpp.

References is_expr_nullable().

1586  {
1587  if (is_expr_nullable(a.get())) {
1588  return true;
1589  }
1590  for (const auto& v : l) {
1591  if (is_expr_nullable(v.get())) {
1592  return true;
1593  }
1594  }
1595  return false;
1596 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1576
constexpr double a
Definition: Utm.h:32

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

1156  {
1157  switch (ti.get_type()) {
1158  case kBOOLEAN:
1159  return constval.tinyintval == NULL_BOOLEAN;
1160  case kTINYINT:
1161  return constval.tinyintval == NULL_TINYINT;
1162  case kINT:
1163  return constval.intval == NULL_INT;
1164  case kSMALLINT:
1165  return constval.smallintval == NULL_SMALLINT;
1166  case kBIGINT:
1167  case kNUMERIC:
1168  case kDECIMAL:
1169  return constval.bigintval == NULL_BIGINT;
1170  case kTIME:
1171  case kTIMESTAMP:
1172  case kDATE:
1173  return constval.bigintval == NULL_BIGINT;
1174  case kVARCHAR:
1175  case kCHAR:
1176  case kTEXT:
1177  return constval.stringval == nullptr;
1178  case kPOINT:
1179  case kLINESTRING:
1180  case kPOLYGON:
1181  case kMULTIPOLYGON:
1182  return constval.stringval == nullptr;
1183  case kFLOAT:
1184  return constval.floatval == NULL_FLOAT;
1185  case kDOUBLE:
1186  return constval.doubleval == NULL_DOUBLE;
1187  case kNULLT:
1188  return constval.bigintval == 0;
1189  case kARRAY:
1190  return constval.arrayval == nullptr;
1191  default:
1192  UNREACHABLE();
1193  }
1194  UNREACHABLE();
1195  return false;
1196 }
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:267
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 755 of file Analyzer.cpp.

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

Definition at line 778 of file Analyzer.cpp.

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

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

Definition at line 767 of file Analyzer.cpp.

767  {
768  static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
769  static_assert(sizeof(TO) < sizeof(FROM));
770  if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
771  static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
772  throw std::runtime_error("Overflow or underflow");
773  }
774  return static_cast<TO>(from);
775 }
template<typename TO , typename FROM >
TO Analyzer::anonymous_namespace{Analyzer.cpp}::safeRound ( FROM const  from)

Definition at line 804 of file Analyzer.cpp.

References anonymous_namespace{Utm.h}::n.

804  {
805  static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
806  constexpr FROM max_float = maxRound<FROM, TO>();
807  FROM const n = std::round(from);
808  if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
809  throw std::runtime_error("Overflow or underflow");
810  }
811  return static_cast<TO>(n);
812 }
constexpr double n
Definition: Utm.h:38
template<typename T >
int64_t Analyzer::anonymous_namespace{Analyzer.cpp}::safeScale ( from,
unsigned const  scale 
)

Definition at line 816 of file Analyzer.cpp.

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

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

+ Here is the caller graph for this function: