OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 1443 of file Analyzer.cpp.

References omnisci.dtypes::T.

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

Definition at line 725 of file Analyzer.cpp.

References omnisci.dtypes::T.

725  {
726  static_assert(std::is_floating_point_v<T>);
727  constexpr auto pow10 = shared::powersOf<T, 16>(10);
728  T num = static_cast<T>(dec);
729  if (scale == 0) {
730  return num;
731  }
732  T den = pow10[scale & 15];
733  for (unsigned sc = scale >> 4; sc; --sc) {
734  den *= 1e16;
735  }
736  return num / den;
737 }
SQLTypes Analyzer::anonymous_namespace{Analyzer.cpp}::get_ti_from_geo ( const Geospatial::GeoBase geo)

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

3299  {
3300  CHECK(geo);
3301  switch (geo->getType()) {
3303  return kPOINT;
3304  }
3306  return kLINESTRING;
3307  }
3309  return kPOLYGON;
3310  }
3312  return kMULTIPOLYGON;
3313  }
3314  default:
3315  UNREACHABLE();
3316  return kNULLT;
3317  }
3318 }
#define UNREACHABLE()
Definition: Logger.h:247
#define CHECK(condition)
Definition: Logger.h:203
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 1560 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().

1560  {
1561  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1562  if (const_expr) {
1563  return const_expr->get_is_null();
1564  }
1565  const auto& expr_ti = expr->get_type_info();
1566  return !expr_ti.get_notnull();
1567 }
bool get_is_null() const
Definition: Analyzer.h:334
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321

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

References is_expr_nullable().

1570  {
1571  if (is_expr_nullable(a.get())) {
1572  return true;
1573  }
1574  for (const auto& v : l) {
1575  if (is_expr_nullable(v.get())) {
1576  return true;
1577  }
1578  }
1579  return false;
1580 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1560

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

1140  {
1141  switch (ti.get_type()) {
1142  case kBOOLEAN:
1143  return constval.tinyintval == NULL_BOOLEAN;
1144  case kTINYINT:
1145  return constval.tinyintval == NULL_TINYINT;
1146  case kINT:
1147  return constval.intval == NULL_INT;
1148  case kSMALLINT:
1149  return constval.smallintval == NULL_SMALLINT;
1150  case kBIGINT:
1151  case kNUMERIC:
1152  case kDECIMAL:
1153  return constval.bigintval == NULL_BIGINT;
1154  case kTIME:
1155  case kTIMESTAMP:
1156  case kDATE:
1157  return constval.bigintval == NULL_BIGINT;
1158  case kVARCHAR:
1159  case kCHAR:
1160  case kTEXT:
1161  return constval.stringval == nullptr;
1162  case kPOINT:
1163  case kLINESTRING:
1164  case kPOLYGON:
1165  case kMULTIPOLYGON:
1166  return constval.stringval == nullptr;
1167  case kFLOAT:
1168  return constval.floatval == NULL_FLOAT;
1169  case kDOUBLE:
1170  return constval.doubleval == NULL_DOUBLE;
1171  case kNULLT:
1172  return constval.bigintval == 0;
1173  case kARRAY:
1174  return constval.arrayval == nullptr;
1175  default:
1176  UNREACHABLE();
1177  }
1178  UNREACHABLE();
1179  return false;
1180 }
int8_t tinyintval
Definition: sqltypes.h:206
#define NULL_DOUBLE
Definition: sqltypes.h:48
#define NULL_FLOAT
#define NULL_BIGINT
VarlenDatum * arrayval
Definition: sqltypes.h:212
#define UNREACHABLE()
Definition: Logger.h:247
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
int32_t intval
Definition: sqltypes.h:208
#define NULL_INT
float floatval
Definition: sqltypes.h:210
int64_t bigintval
Definition: sqltypes.h:209
int16_t smallintval
Definition: sqltypes.h:207
#define NULL_BOOLEAN
std::string * stringval
Definition: sqltypes.h:214
Definition: sqltypes.h:51
Definition: sqltypes.h:52
Definition: sqltypes.h:40
#define NULL_TINYINT
#define NULL_SMALLINT
Definition: sqltypes.h:44
double doubleval
Definition: sqltypes.h:211

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

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

Definition at line 769 of file Analyzer.cpp.

References omnisci.dtypes::T.

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

Definition at line 758 of file Analyzer.cpp.

References FROM, and TO.

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

Definition at line 795 of file Analyzer.cpp.

References FROM, and TO.

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

Definition at line 807 of file Analyzer.cpp.

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

807  {
808  static_assert(std::is_arithmetic_v<T>);
809  constexpr size_t max_scale = std::numeric_limits<int64_t>::digits10; // 18
810  constexpr auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
811  if constexpr (std::is_integral_v<T>) {
812  int64_t retval;
813  if (scale < pow10.size() && !__builtin_mul_overflow(from, pow10[scale], &retval)) {
814  return retval;
815  }
816  } else if constexpr (std::is_floating_point_v<T>) {
817  if (scale < pow10.size()) {
818  return safeRound<int64_t>(from * pow10[scale]);
819  }
820  }
821  if (from == 0) {
822  return 0;
823  }
824  throw std::runtime_error("Overflow or underflow");
825 }

+ Here is the caller graph for this function: