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

Functions

bool has_same_dict (const SQLTypeInfo &type1, const SQLTypeInfo &type2)
 
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 1520 of file Analyzer.cpp.

References heavydb.dtypes::T.

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

Definition at line 796 of file Analyzer.cpp.

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

796  {
797  static_assert(std::is_floating_point_v<T>);
798  return static_cast<T>(dec) / shared::power10(scale);
799 }
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 3790 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().

3790  {
3791  CHECK(geo);
3792  switch (geo->getType()) {
3794  return kPOINT;
3795  }
3797  return kMULTIPOINT;
3798  }
3800  return kLINESTRING;
3801  }
3803  return kMULTILINESTRING;
3804  }
3806  return kPOLYGON;
3807  }
3809  return kMULTIPOLYGON;
3810  }
3811  default:
3812  UNREACHABLE();
3813  return kNULLT;
3814  }
3815 }
#define UNREACHABLE()
Definition: Logger.h:337
#define CHECK(condition)
Definition: Logger.h:291
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}::has_same_dict ( const SQLTypeInfo type1,
const SQLTypeInfo type2 
)

Definition at line 426 of file Analyzer.cpp.

References SQLTypeInfo::getStringDictKey(), and TRANSIENT_DICT.

Referenced by Analyzer::Expr::add_cast(), Analyzer::UOper::add_cast(), and Analyzer::BinOper::common_string_type().

426  {
427  const auto& type1_dict_key = type1.getStringDictKey();
428  const auto& type2_dict_key = type2.getStringDictKey();
429  return (type1_dict_key == type2_dict_key ||
430  (type1_dict_key.db_id == type2_dict_key.db_id &&
431  type1_dict_key.dict_id == TRANSIENT_DICT(type2_dict_key.dict_id)));
432 }
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:312
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1021

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

1637  {
1638  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1639  if (const_expr) {
1640  return const_expr->get_is_null();
1641  }
1642  const auto& expr_ti = expr->get_type_info();
1643  return !expr_ti.get_notnull();
1644 }
bool get_is_null() const
Definition: Analyzer.h:347
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:388

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

References is_expr_nullable().

1647  {
1648  if (is_expr_nullable(a.get())) {
1649  return true;
1650  }
1651  for (const auto& v : l) {
1652  if (is_expr_nullable(v.get())) {
1653  return true;
1654  }
1655  }
1656  return false;
1657 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1637
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 1209 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().

1209  {
1210  switch (ti.get_type()) {
1211  case kBOOLEAN:
1212  return constval.tinyintval == NULL_BOOLEAN;
1213  case kTINYINT:
1214  return constval.tinyintval == NULL_TINYINT;
1215  case kINT:
1216  return constval.intval == NULL_INT;
1217  case kSMALLINT:
1218  return constval.smallintval == NULL_SMALLINT;
1219  case kBIGINT:
1220  case kNUMERIC:
1221  case kDECIMAL:
1222  return constval.bigintval == NULL_BIGINT;
1223  case kTIME:
1224  case kTIMESTAMP:
1225  case kDATE:
1226  case kINTERVAL_DAY_TIME:
1227  case kINTERVAL_YEAR_MONTH:
1228  return constval.bigintval == NULL_BIGINT;
1229  case kVARCHAR:
1230  case kCHAR:
1231  case kTEXT:
1232  return constval.stringval == nullptr;
1233  case kPOINT:
1234  case kMULTIPOINT:
1235  case kLINESTRING:
1236  case kMULTILINESTRING:
1237  case kPOLYGON:
1238  case kMULTIPOLYGON:
1239  return constval.stringval == nullptr;
1240  case kFLOAT:
1241  return constval.floatval == NULL_FLOAT;
1242  case kDOUBLE:
1243  return constval.doubleval == NULL_DOUBLE;
1244  case kNULLT:
1245  return constval.bigintval == 0;
1246  case kARRAY:
1247  return constval.arrayval == nullptr;
1248  default:
1249  UNREACHABLE();
1250  }
1251  UNREACHABLE();
1252  return false;
1253 }
int8_t tinyintval
Definition: Datum.h:69
#define NULL_DOUBLE
Definition: sqltypes.h:66
#define NULL_FLOAT
#define NULL_BIGINT
VarlenDatum * arrayval
Definition: Datum.h:75
#define UNREACHABLE()
Definition: Logger.h:337
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
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:69
Definition: sqltypes.h:70
Definition: sqltypes.h:58
#define NULL_TINYINT
#define NULL_SMALLINT
Definition: sqltypes.h:62
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 808 of file Analyzer.cpp.

808  {
809  static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
810  constexpr int dd =
811  std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
812  if constexpr (0 < dd) { // NOLINT
813  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
814  } else {
815  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max());
816  }
817 }
template<typename T >
T Analyzer::anonymous_namespace{Analyzer.cpp}::roundDecimal ( int64_t  n,
unsigned  scale 
)

Definition at line 831 of file Analyzer.cpp.

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

831  {
832  static_assert(std::is_integral_v<T>);
833  constexpr size_t max_scale = std::numeric_limits<uint64_t>::digits10; // 19
834  constexpr auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
835  if (scale == 0) {
836  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
837  return safeNarrow<T>(n);
838  } else {
839  return n;
840  }
841  } else if (max_scale < scale) {
842  return 0; // 0.09223372036854775807 rounds to 0
843  }
844  uint64_t const u = std::abs(n);
845  uint64_t const pow = pow10[scale];
846  uint64_t div = u / pow;
847  uint64_t rem = u % pow;
848  div += pow / 2 <= rem;
849  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
850  return safeNarrow<T>(static_cast<int64_t>(n < 0 ? -div : div));
851  } else {
852  return n < 0 ? -div : div;
853  }
854 }
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 820 of file Analyzer.cpp.

820  {
821  static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
822  static_assert(sizeof(TO) < sizeof(FROM));
823  if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
824  static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
825  throw std::runtime_error("Overflow or underflow");
826  }
827  return static_cast<TO>(from);
828 }
template<typename TO , typename FROM >
TO Analyzer::anonymous_namespace{Analyzer.cpp}::safeRound ( FROM const  from)

Definition at line 857 of file Analyzer.cpp.

References anonymous_namespace{Utm.h}::n.

857  {
858  static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
859  constexpr FROM max_float = maxRound<FROM, TO>();
860  FROM const n = std::round(from);
861  if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
862  throw std::runtime_error("Overflow or underflow");
863  }
864  return static_cast<TO>(n);
865 }
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 869 of file Analyzer.cpp.

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

869  {
870  static_assert(std::is_arithmetic_v<T>);
871  constexpr size_t max_scale = std::numeric_limits<int64_t>::digits10; // 18
872  constexpr auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
873  if constexpr (std::is_integral_v<T>) { // NOLINT
874  int64_t retval;
875  if (scale < pow10.size()) {
876 #ifdef __linux__
877  if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
878  return retval;
879  }
880  // Not over flow safe.
881 #else
882  return from * pow10[scale];
883 #endif
884  }
885  } else if constexpr (std::is_floating_point_v<T>) {
886  if (scale < pow10.size()) {
887  return safeRound<int64_t>(from * pow10[scale]);
888  }
889  }
890  if (from == 0) {
891  return 0;
892  }
893  throw std::runtime_error("Overflow or underflow");
894 }

+ Here is the caller graph for this function: