OmniSciDB  72c90bc290
 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)
 
SQLTypeInfo make_transient_dict_type (SQLTypeInfo sql_type_info_copy)
 
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)
 
int32_t ordered_bucket (double const lower_bound, double const upper_bound, int32_t const partition_count, double const value)
 
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 1547 of file Analyzer.cpp.

References heavydb.dtypes::T.

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

Definition at line 820 of file Analyzer.cpp.

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

820  {
821  static_assert(std::is_floating_point_v<T>);
822  return static_cast<T>(dec) / shared::power10(scale);
823 }
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 3984 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().

3984  {
3985  CHECK(geo);
3986  switch (geo->getType()) {
3988  return kPOINT;
3989  }
3991  return kMULTIPOINT;
3992  }
3994  return kLINESTRING;
3995  }
3997  return kMULTILINESTRING;
3998  }
4000  return kPOLYGON;
4001  }
4003  return kMULTIPOLYGON;
4004  }
4005  default:
4006  UNREACHABLE();
4007  return kNULLT;
4008  }
4009 }
#define UNREACHABLE()
Definition: Logger.h:338
#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 443 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().

443  {
444  const auto& type1_dict_key = type1.getStringDictKey();
445  const auto& type2_dict_key = type2.getStringDictKey();
446  return (type1_dict_key == type2_dict_key ||
447  (type1_dict_key.db_id == type2_dict_key.db_id &&
448  type1_dict_key.dict_id == TRANSIENT_DICT(type2_dict_key.dict_id)));
449 }
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:322
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1055

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

1664  {
1665  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1666  if (const_expr) {
1667  return const_expr->get_is_null();
1668  }
1669  const auto& expr_ti = expr->get_type_info();
1670  return !expr_ti.get_notnull();
1671 }
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:398

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

References is_expr_nullable().

1674  {
1675  if (is_expr_nullable(a.get())) {
1676  return true;
1677  }
1678  for (const auto& v : l) {
1679  if (is_expr_nullable(v.get())) {
1680  return true;
1681  }
1682  }
1683  return false;
1684 }
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1664
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 1233 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().

1233  {
1234  switch (ti.get_type()) {
1235  case kBOOLEAN:
1236  return constval.tinyintval == NULL_BOOLEAN;
1237  case kTINYINT:
1238  return constval.tinyintval == NULL_TINYINT;
1239  case kINT:
1240  return constval.intval == NULL_INT;
1241  case kSMALLINT:
1242  return constval.smallintval == NULL_SMALLINT;
1243  case kBIGINT:
1244  case kNUMERIC:
1245  case kDECIMAL:
1246  return constval.bigintval == NULL_BIGINT;
1247  case kTIME:
1248  case kTIMESTAMP:
1249  case kDATE:
1250  case kINTERVAL_DAY_TIME:
1251  case kINTERVAL_YEAR_MONTH:
1252  return constval.bigintval == NULL_BIGINT;
1253  case kVARCHAR:
1254  case kCHAR:
1255  case kTEXT:
1256  return constval.stringval == nullptr;
1257  case kPOINT:
1258  case kMULTIPOINT:
1259  case kLINESTRING:
1260  case kMULTILINESTRING:
1261  case kPOLYGON:
1262  case kMULTIPOLYGON:
1263  return constval.stringval == nullptr;
1264  case kFLOAT:
1265  return constval.floatval == NULL_FLOAT;
1266  case kDOUBLE:
1267  return constval.doubleval == NULL_DOUBLE;
1268  case kNULLT:
1269  return constval.bigintval == 0;
1270  case kARRAY:
1271  return constval.arrayval == nullptr;
1272  default:
1273  UNREACHABLE();
1274  }
1275  UNREACHABLE();
1276  return false;
1277 }
int8_t tinyintval
Definition: Datum.h:71
#define NULL_DOUBLE
Definition: sqltypes.h:76
#define NULL_FLOAT
#define NULL_BIGINT
VarlenDatum * arrayval
Definition: Datum.h:77
#define UNREACHABLE()
Definition: Logger.h:338
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
int32_t intval
Definition: Datum.h:73
#define NULL_INT
float floatval
Definition: Datum.h:75
int64_t bigintval
Definition: Datum.h:74
int16_t smallintval
Definition: Datum.h:72
#define NULL_BOOLEAN
std::string * stringval
Definition: Datum.h:79
Definition: sqltypes.h:79
Definition: sqltypes.h:80
Definition: sqltypes.h:68
#define NULL_TINYINT
#define NULL_SMALLINT
Definition: sqltypes.h:72
double doubleval
Definition: Datum.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypeInfo Analyzer::anonymous_namespace{Analyzer.cpp}::make_transient_dict_type ( SQLTypeInfo  sql_type_info_copy)

Definition at line 764 of file Analyzer.cpp.

References kENCODING_DICT, kTEXT, shared::StringDictKey::kTransientDictKey, SQLTypeInfo::set_comp_param(), SQLTypeInfo::set_compression(), SQLTypeInfo::set_fixed_size(), SQLTypeInfo::set_type(), SQLTypeInfo::setStringDictKey(), and TRANSIENT_DICT_ID.

Referenced by Analyzer::Expr::add_cast(), and Analyzer::GeoOperator::add_cast().

764  {
765  sql_type_info_copy.set_type(kTEXT);
766  sql_type_info_copy.set_compression(kENCODING_DICT);
767  sql_type_info_copy.set_comp_param(TRANSIENT_DICT_ID);
769  sql_type_info_copy.set_fixed_size();
770  return sql_type_info_copy;
771 }
void set_compression(EncodingType c)
Definition: sqltypes.h:479
#define TRANSIENT_DICT_ID
Definition: DbObjectKeys.h:24
void set_fixed_size()
Definition: sqltypes.h:477
void set_comp_param(int p)
Definition: sqltypes.h:480
Definition: sqltypes.h:79
void setStringDictKey(const shared::StringDictKey &dict_key)
Definition: sqltypes.h:1061
static const StringDictKey kTransientDictKey
Definition: DbObjectKeys.h:45
HOST DEVICE void set_type(SQLTypes t)
Definition: sqltypes.h:468

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

832  {
833  static_assert(std::is_integral_v<INT_TYPE> && std::is_floating_point_v<FLOAT_TYPE>);
834  constexpr int dd =
835  std::numeric_limits<INT_TYPE>::digits - std::numeric_limits<FLOAT_TYPE>::digits;
836  if constexpr (0 < dd) { // NOLINT
837  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max() - (1ll << dd));
838  } else {
839  return static_cast<FLOAT_TYPE>(std::numeric_limits<INT_TYPE>::max());
840  }
841 }
int32_t Analyzer::anonymous_namespace{Analyzer.cpp}::ordered_bucket ( double const  lower_bound,
double const  upper_bound,
int32_t const  partition_count,
double const  value 
)

Definition at line 3951 of file Analyzer.cpp.

References gpu_enabled::lower_bound(), and width.

Referenced by Analyzer::WidthBucketExpr::compute_bucket().

3954  {
3955  if (value < lower_bound) {
3956  return 0;
3957  } else if (upper_bound <= value) {
3958  return partition_count + 1;
3959  } else { // There is no division by 0 since a previous return would have occurred.
3960  double const width = upper_bound - lower_bound;
3961  return static_cast<int32_t>(partition_count * (value - lower_bound) / width) + 1;
3962  }
3963 }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T >
T Analyzer::anonymous_namespace{Analyzer.cpp}::roundDecimal ( int64_t  n,
unsigned  scale 
)

Definition at line 855 of file Analyzer.cpp.

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

855  {
856  static_assert(std::is_integral_v<T>);
857  constexpr size_t max_scale = std::numeric_limits<uint64_t>::digits10; // 19
858  constexpr auto pow10 = shared::powersOf<uint64_t, max_scale + 1>(10);
859  if (scale == 0) {
860  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
861  return safeNarrow<T>(n);
862  } else {
863  return n;
864  }
865  } else if (max_scale < scale) {
866  return 0; // 0.09223372036854775807 rounds to 0
867  }
868  uint64_t const u = std::abs(n);
869  uint64_t const pow = pow10[scale];
870  uint64_t div = u / pow;
871  uint64_t rem = u % pow;
872  div += pow / 2 <= rem;
873  if constexpr (sizeof(T) < sizeof(int64_t)) { // NOLINT
874  return safeNarrow<T>(static_cast<int64_t>(n < 0 ? -div : div));
875  } else {
876  return n < 0 ? -div : div;
877  }
878 }
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 844 of file Analyzer.cpp.

844  {
845  static_assert(std::is_integral_v<TO> && std::is_integral_v<FROM>);
846  static_assert(sizeof(TO) < sizeof(FROM));
847  if (from < static_cast<FROM>(std::numeric_limits<TO>::min()) ||
848  static_cast<FROM>(std::numeric_limits<TO>::max()) < from) {
849  throw std::runtime_error("Overflow or underflow");
850  }
851  return static_cast<TO>(from);
852 }
template<typename TO , typename FROM >
TO Analyzer::anonymous_namespace{Analyzer.cpp}::safeRound ( FROM const  from)

Definition at line 881 of file Analyzer.cpp.

References anonymous_namespace{Utm.h}::n.

881  {
882  static_assert(std::is_integral_v<TO> && std::is_floating_point_v<FROM>);
883  constexpr FROM max_float = maxRound<FROM, TO>();
884  FROM const n = std::round(from);
885  if (n < static_cast<FROM>(std::numeric_limits<TO>::min()) || max_float < n) {
886  throw std::runtime_error("Overflow or underflow");
887  }
888  return static_cast<TO>(n);
889 }
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 893 of file Analyzer.cpp.

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

893  {
894  static_assert(std::is_arithmetic_v<T>);
895  constexpr size_t max_scale = std::numeric_limits<int64_t>::digits10; // 18
896  constexpr auto pow10 = shared::powersOf<int64_t, max_scale + 1>(10);
897  if constexpr (std::is_integral_v<T>) { // NOLINT
898  int64_t retval;
899  if (scale < pow10.size()) {
900 #ifdef __linux__
901  if (!__builtin_mul_overflow(from, pow10[scale], &retval)) {
902  return retval;
903  }
904  // Not over flow safe.
905 #else
906  return from * pow10[scale];
907 #endif
908  }
909  } else if constexpr (std::is_floating_point_v<T>) {
910  if (scale < pow10.size()) {
911  return safeRound<int64_t>(from * pow10[scale]);
912  }
913  }
914  if (from == 0) {
915  return 0;
916  }
917  throw std::runtime_error("Overflow or underflow");
918 }

+ Here is the caller graph for this function: