OmniSciDB  a987f07e93
 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 1504 of file Analyzer.cpp.

References heavydb.dtypes::T.

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

Definition at line 779 of file Analyzer.cpp.

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

779  {
780  static_assert(std::is_floating_point_v<T>);
781  return static_cast<T>(dec) / shared::power10(scale);
782 }
double power10(unsigned const x)
Definition: misc.h:275

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

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

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

3775  {
3776  CHECK(geo);
3777  switch (geo->getType()) {
3779  return kPOINT;
3780  }
3782  return kMULTIPOINT;
3783  }
3785  return kLINESTRING;
3786  }
3788  return kMULTILINESTRING;
3789  }
3791  return kPOLYGON;
3792  }
3794  return kMULTIPOLYGON;
3795  }
3796  default:
3797  UNREACHABLE();
3798  return kNULLT;
3799  }
3800 }
#define UNREACHABLE()
Definition: Logger.h:333
#define CHECK(condition)
Definition: Logger.h:289
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 1621 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().

1621  {
1622  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1623  if (const_expr) {
1624  return const_expr->get_is_null();
1625  }
1626  const auto& expr_ti = expr->get_type_info();
1627  return !expr_ti.get_notnull();
1628 }
bool get_is_null() const
Definition: Analyzer.h:343
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:83
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:387

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

References is_expr_nullable().

1631  {
1632  if (is_expr_nullable(a.get())) {
1633  return true;
1634  }
1635  for (const auto& v : l) {
1636  if (is_expr_nullable(v.get())) {
1637  return true;
1638  }
1639  }
1640  return false;
1641 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1621
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 1192 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, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, 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().

1192  {
1193  switch (ti.get_type()) {
1194  case kBOOLEAN:
1195  return constval.tinyintval == NULL_BOOLEAN;
1196  case kTINYINT:
1197  return constval.tinyintval == NULL_TINYINT;
1198  case kINT:
1199  return constval.intval == NULL_INT;
1200  case kSMALLINT:
1201  return constval.smallintval == NULL_SMALLINT;
1202  case kBIGINT:
1203  case kNUMERIC:
1204  case kDECIMAL:
1205  return constval.bigintval == NULL_BIGINT;
1206  case kTIME:
1207  case kTIMESTAMP:
1208  case kDATE:
1209  case kINTERVAL_DAY_TIME:
1210  case kINTERVAL_YEAR_MONTH:
1211  return constval.bigintval == NULL_BIGINT;
1212  case kVARCHAR:
1213  case kCHAR:
1214  case kTEXT:
1215  return constval.stringval == nullptr;
1216  case kPOINT:
1217  case kMULTIPOINT:
1218  case kLINESTRING:
1219  case kMULTILINESTRING:
1220  case kPOLYGON:
1221  case kMULTIPOLYGON:
1222  return constval.stringval == nullptr;
1223  case kFLOAT:
1224  return constval.floatval == NULL_FLOAT;
1225  case kDOUBLE:
1226  return constval.doubleval == NULL_DOUBLE;
1227  case kNULLT:
1228  return constval.bigintval == 0;
1229  case kARRAY:
1230  return constval.arrayval == nullptr;
1231  default:
1232  UNREACHABLE();
1233  }
1234  UNREACHABLE();
1235  return false;
1236 }
int8_t tinyintval
Definition: Datum.h:69
#define NULL_DOUBLE
Definition: sqltypes.h:64
#define NULL_FLOAT
#define NULL_BIGINT
VarlenDatum * arrayval
Definition: Datum.h:75
#define UNREACHABLE()
Definition: Logger.h:333
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
int32_t intval
Definition: Datum.h:71
#define NULL_INT
float floatval
Definition: Datum.h:73
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
#define NULL_BOOLEAN
std::string * stringval
Definition: Datum.h:77
Definition: sqltypes.h:67
Definition: sqltypes.h:68
Definition: sqltypes.h:56
#define NULL_TINYINT
#define NULL_SMALLINT
Definition: sqltypes.h:60
double doubleval
Definition: Datum.h:74

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

791  {
792  static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
793  constexpr int dd =
794  std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
795  if constexpr (0 < dd) { // NOLINT
796  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
797  } else {
798  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max());
799  }
800 }
template<typename T >
T Analyzer::anonymous_namespace{Analyzer.cpp}::roundDecimal ( int64_t  n,
unsigned  scale 
)

Definition at line 814 of file Analyzer.cpp.

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

814  {
815  static_assert(std::is_integral_v<T>);
816  constexpr size_t max_scale = std::numeric_limits<uint64_t>::digits10; // 19
817  constexpr auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
818  if (scale == 0) {
819  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
820  return safeNarrow<T>(n);
821  } else {
822  return n;
823  }
824  } else if (max_scale < scale) {
825  return 0; // 0.09223372036854775807 rounds to 0
826  }
827  uint64_t const u = std::abs(n);
828  uint64_t const pow = pow10[scale];
829  uint64_t div = u / pow;
830  uint64_t rem = u % pow;
831  div += pow / 2 <= rem;
832  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
833  return safeNarrow<T>(static_cast<int64_t>(n < 0 ? -div : div));
834  } else {
835  return n < 0 ? -div : div;
836  }
837 }
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 803 of file Analyzer.cpp.

803  {
804  static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
805  static_assert(sizeof(TO) < sizeof(FROM));
806  if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
807  static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
808  throw std::runtime_error("Overflow or underflow");
809  }
810  return static_cast<TO>(from);
811 }
template<typename TO , typename FROM >
TO Analyzer::anonymous_namespace{Analyzer.cpp}::safeRound ( FROM const  from)

Definition at line 840 of file Analyzer.cpp.

References anonymous_namespace{Utm.h}::n.

840  {
841  static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
842  constexpr FROM max_float = maxRound<FROM, TO>();
843  FROM const n = std::round(from);
844  if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
845  throw std::runtime_error("Overflow or underflow");
846  }
847  return static_cast<TO>(n);
848 }
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 852 of file Analyzer.cpp.

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

852  {
853  static_assert(std::is_arithmetic_v<T>);
854  constexpr size_t max_scale = std::numeric_limits<int64_t>::digits10; // 18
855  constexpr auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
856  if constexpr (std::is_integral_v<T>) { // NOLINT
857  int64_t retval;
858  if (scale < pow10.size()) {
859 #ifdef __linux__
860  if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
861  return retval;
862  }
863  // Not over flow safe.
864 #else
865  return from * pow10[scale];
866 #endif
867  }
868  } else if constexpr (std::is_floating_point_v<T>) {
869  if (scale < pow10.size()) {
870  return safeRound<int64_t>(from * pow10[scale]);
871  }
872  }
873  if (from == 0) {
874  return 0;
875  }
876  throw std::runtime_error("Overflow or underflow");
877 }

+ Here is the caller graph for this function: