OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::Constant Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::Constant:
+ Collaboration diagram for Analyzer::Constant:

Public Member Functions

 Constant (SQLTypes t, bool n)
 
 Constant (SQLTypes t, bool n, Datum v)
 
 Constant (const SQLTypeInfo &ti, bool n, Datum v)
 
 Constant (const SQLTypeInfo &ti, bool n, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
 
 ~Constant () override
 
bool get_is_null () const
 
Datum get_constval () const
 
void set_constval (Datum d)
 
const std::list
< std::shared_ptr
< Analyzer::Expr > > & 
get_value_list () const
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
std::shared_ptr< Analyzer::Expradd_cast (const SQLTypeInfo &new_type_info) override
 
bool operator== (const Expr &rhs) const override
 
std::string toString () const override
 
- Public Member Functions inherited from Analyzer::Expr
 Expr (SQLTypes t, bool notnull)
 
 Expr (SQLTypes t, int d, bool notnull)
 
 Expr (SQLTypes t, int d, int s, bool notnull)
 
 Expr (const SQLTypeInfo &ti, bool has_agg=false)
 
virtual ~Expr ()
 
std::shared_ptr< Analyzer::Exprget_shared_ptr ()
 
const SQLTypeInfoget_type_info () const
 
void set_type_info (const SQLTypeInfo &ti)
 
bool get_contains_agg () const
 
void set_contains_agg (bool a)
 
virtual void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
 
virtual std::shared_ptr
< Analyzer::Expr
normalize_simple_predicate (int &rte_idx) const
 
virtual void group_predicates (std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const
 
virtual void collect_rte_idx (std::set< int > &rte_idx_set) const
 
virtual void collect_column_var (std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const
 
virtual size_t get_num_column_vars (const bool include_agg) const
 
virtual std::shared_ptr
< Analyzer::Expr
rewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual std::shared_ptr
< Analyzer::Expr
rewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual std::shared_ptr
< Analyzer::Expr
rewrite_agg_to_var (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr * > &expr_list) const
 
virtual void find_expr (std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Protected Member Functions

void cast_number (const SQLTypeInfo &new_type_info)
 
void cast_string (const SQLTypeInfo &new_type_info)
 
void cast_from_string (const SQLTypeInfo &new_type_info)
 
void cast_to_string (const SQLTypeInfo &new_type_info)
 
void do_cast (const SQLTypeInfo &new_type_info)
 
void set_null_value ()
 

Protected Attributes

bool is_null
 
Datum constval
 
const std::list
< std::shared_ptr
< Analyzer::Expr > > 
value_list
 
- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 319 of file Analyzer.h.

Constructor & Destructor Documentation

Analyzer::Constant::Constant ( SQLTypes  t,
bool  n 
)
inline

Definition at line 321 of file Analyzer.h.

References SQLTypeInfo::set_notnull(), set_null_value(), and Analyzer::Expr::type_info.

321  : Expr(t, !n), is_null(n) {
322  if (n) {
323  set_null_value();
324  } else {
325  type_info.set_notnull(true);
326  }
327  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
SQLTypeInfo type_info
Definition: Analyzer.h:180
void set_notnull(bool n)
Definition: sqltypes.h:475
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

Analyzer::Constant::Constant ( SQLTypes  t,
bool  n,
Datum  v 
)
inline

Definition at line 328 of file Analyzer.h.

References SQLTypeInfo::set_notnull(), set_null_value(), and Analyzer::Expr::type_info.

328  : Expr(t, !n), is_null(n), constval(v) {
329  if (n) {
330  set_null_value();
331  } else {
332  type_info.set_notnull(true);
333  }
334  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
SQLTypeInfo type_info
Definition: Analyzer.h:180
void set_notnull(bool n)
Definition: sqltypes.h:475
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

Analyzer::Constant::Constant ( const SQLTypeInfo ti,
bool  n,
Datum  v 
)
inline

Definition at line 335 of file Analyzer.h.

References SQLTypeInfo::set_notnull(), set_null_value(), and Analyzer::Expr::type_info.

335  : Expr(ti), is_null(n), constval(v) {
336  if (n) {
337  set_null_value();
338  } else {
339  type_info.set_notnull(true);
340  }
341  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
SQLTypeInfo type_info
Definition: Analyzer.h:180
void set_notnull(bool n)
Definition: sqltypes.h:475
constexpr double n
Definition: Utm.h:38

+ Here is the call graph for this function:

Analyzer::Constant::Constant ( const SQLTypeInfo ti,
bool  n,
const std::list< std::shared_ptr< Analyzer::Expr >> &  l 
)
inline

Definition at line 342 of file Analyzer.h.

345  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:361
constexpr double n
Definition: Utm.h:38
Definition: Datum.h:69
Constant::~Constant ( )
override

Definition at line 40 of file Analyzer.cpp.

References constval, SQLTypeInfo::is_geometry(), is_null, SQLTypeInfo::is_string(), Datum::stringval, and Analyzer::Expr::type_info.

40  {
41  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
42  delete constval.stringval;
43  }
44 }
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string * stringval
Definition: Datum.h:79
bool is_geometry() const
Definition: sqltypes.h:595
bool is_string() const
Definition: sqltypes.h:559

+ Here is the call graph for this function:

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Constant::add_cast ( const SQLTypeInfo new_type_info)
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1416 of file Analyzer.cpp.

References Analyzer::Expr::add_cast(), Analyzer::Expr::contains_agg, do_cast(), SQLTypeInfo::get_compression(), SQLTypeInfo::is_date(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_integer(), is_null, SQLTypeInfo::is_time(), kCAST, kENCODING_DATE_IN_DAYS, kENCODING_NONE, SQLTypeInfo::set_compression(), set_null_value(), and Analyzer::Expr::type_info.

1416  {
1417  if (is_null) {
1418  type_info = new_type_info;
1419  set_null_value();
1420  return shared_from_this();
1421  }
1422  if (new_type_info.get_compression() != type_info.get_compression()) {
1423  if (new_type_info.get_compression() != kENCODING_NONE) {
1424  SQLTypeInfo new_ti = new_type_info;
1425  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1427  }
1428  do_cast(new_ti);
1429  }
1430  return Expr::add_cast(new_type_info);
1431  }
1432  const auto is_integral_type =
1433  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1434  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1435  // Let the codegen phase deal with casts from date/time to a number.
1436  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1437  }
1438  do_cast(new_type_info);
1439  return shared_from_this();
1440 }
void set_compression(EncodingType c)
Definition: sqltypes.h:479
bool is_fp() const
Definition: sqltypes.h:571
Definition: sqldefs.h:48
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool is_time() const
Definition: sqltypes.h:577
bool is_integer() const
Definition: sqltypes.h:565
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1281
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:774
bool contains_agg
Definition: Analyzer.h:181
bool is_decimal() const
Definition: sqltypes.h:568
bool is_date() const
Definition: sqltypes.h:1026

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1208 of file Analyzer.cpp.

References constval, StringToDatum(), Datum::stringval, and Analyzer::Expr::type_info.

Referenced by do_cast().

1208  {
1209  std::string* s = constval.stringval;
1210  SQLTypeInfo ti = new_type_info;
1211  constval = StringToDatum(*s, ti);
1212  delete s;
1213  type_info = new_type_info;
1214 }
SQLTypeInfo type_info
Definition: Analyzer.h:180
Datum StringToDatum(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:339
std::string * stringval
Definition: Datum.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Constant::cast_number ( const SQLTypeInfo new_type_info)
protected

Definition at line 922 of file Analyzer.cpp.

References Datum::bigintval, Datum::boolval, CHECK, constval, convert_decimal_value_to_scale(), Datum::doubleval, Datum::floatval, SQLTypeInfo::get_scale(), SQLTypeInfo::get_type(), Datum::intval, kBIGINT, kBOOLEAN, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTIMESTAMP, kTINYINT, Analyzer::anonymous_namespace{Analyzer.cpp}::safeScale(), Datum::smallintval, Datum::tinyintval, and Analyzer::Expr::type_info.

Referenced by do_cast().

922  {
923  switch (type_info.get_type()) {
924  case kTINYINT:
925  switch (new_type_info.get_type()) {
926  case kTINYINT:
927  break;
928  case kINT:
929  constval.intval = (int32_t)constval.tinyintval;
930  break;
931  case kSMALLINT:
933  break;
934  case kBIGINT:
935  case kTIMESTAMP:
937  break;
938  case kDOUBLE:
940  break;
941  case kFLOAT:
943  break;
944  case kNUMERIC:
945  case kDECIMAL:
947  break;
948  default:
949  CHECK(false);
950  }
951  break;
952  case kINT:
953  switch (new_type_info.get_type()) {
954  case kTINYINT:
955  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
956  break;
957  case kINT:
958  break;
959  case kSMALLINT:
960  constval.smallintval = safeNarrow<int16_t>(constval.intval);
961  break;
962  case kBIGINT:
963  case kTIMESTAMP:
964  constval.bigintval = (int64_t)constval.intval;
965  break;
966  case kDOUBLE:
967  constval.doubleval = (double)constval.intval;
968  break;
969  case kFLOAT:
970  constval.floatval = (float)constval.intval;
971  break;
972  case kNUMERIC:
973  case kDECIMAL:
974  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
975  break;
976  default:
977  CHECK(false);
978  }
979  break;
980  case kSMALLINT:
981  switch (new_type_info.get_type()) {
982  case kTINYINT:
983  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
984  break;
985  case kINT:
986  constval.intval = (int32_t)constval.smallintval;
987  break;
988  case kSMALLINT:
989  break;
990  case kBIGINT:
991  case kTIMESTAMP:
993  break;
994  case kDOUBLE:
996  break;
997  case kFLOAT:
999  break;
1000  case kNUMERIC:
1001  case kDECIMAL:
1003  break;
1004  default:
1005  CHECK(false);
1006  }
1007  break;
1008  case kBIGINT:
1009  switch (new_type_info.get_type()) {
1010  case kTINYINT:
1011  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1012  break;
1013  case kINT:
1014  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1015  break;
1016  case kSMALLINT:
1017  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1018  break;
1019  case kBIGINT:
1020  case kTIMESTAMP:
1021  break;
1022  case kDOUBLE:
1024  break;
1025  case kFLOAT:
1027  break;
1028  case kNUMERIC:
1029  case kDECIMAL:
1031  break;
1032  default:
1033  CHECK(false);
1034  }
1035  break;
1036  case kDOUBLE:
1037  switch (new_type_info.get_type()) {
1038  case kTINYINT:
1039  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
1040  break;
1041  case kINT:
1042  constval.intval = safeRound<int32_t>(constval.doubleval);
1043  break;
1044  case kSMALLINT:
1045  constval.smallintval = safeRound<int16_t>(constval.doubleval);
1046  break;
1047  case kBIGINT:
1048  case kTIMESTAMP:
1049  constval.bigintval = safeRound<int64_t>(constval.doubleval);
1050  break;
1051  case kDOUBLE:
1052  break;
1053  case kFLOAT:
1055  break;
1056  case kNUMERIC:
1057  case kDECIMAL:
1059  break;
1060  default:
1061  CHECK(false);
1062  }
1063  break;
1064  case kFLOAT:
1065  switch (new_type_info.get_type()) {
1066  case kTINYINT:
1067  constval.tinyintval = safeRound<int8_t>(constval.floatval);
1068  break;
1069  case kINT:
1070  constval.intval = safeRound<int32_t>(constval.floatval);
1071  break;
1072  case kSMALLINT:
1073  constval.smallintval = safeRound<int16_t>(constval.floatval);
1074  break;
1075  case kBIGINT:
1076  case kTIMESTAMP:
1077  constval.bigintval = safeRound<int64_t>(constval.floatval);
1078  break;
1079  case kDOUBLE:
1080  constval.doubleval = (double)constval.floatval;
1081  break;
1082  case kFLOAT:
1083  break;
1084  case kNUMERIC:
1085  case kDECIMAL:
1086  constval.bigintval = safeScale(constval.floatval, new_type_info.get_scale());
1087  break;
1088  default:
1089  CHECK(false);
1090  }
1091  break;
1092  case kNUMERIC:
1093  case kDECIMAL:
1094  switch (new_type_info.get_type()) {
1095  case kTINYINT:
1097  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1098  break;
1099  case kINT:
1100  constval.intval =
1101  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1102  break;
1103  case kSMALLINT:
1105  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1106  break;
1107  case kBIGINT:
1108  case kTIMESTAMP:
1110  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1111  break;
1112  case kDOUBLE:
1114  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1115  break;
1116  case kFLOAT:
1117  constval.floatval =
1118  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1119  break;
1120  case kNUMERIC:
1121  case kDECIMAL:
1123  constval.bigintval, type_info, new_type_info);
1124  break;
1125  default:
1126  CHECK(false);
1127  }
1128  break;
1129  case kTIMESTAMP:
1130  switch (new_type_info.get_type()) {
1131  case kTINYINT:
1132  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1133  break;
1134  case kINT:
1135  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1136  break;
1137  case kSMALLINT:
1138  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1139  break;
1140  case kBIGINT:
1141  case kTIMESTAMP:
1142  break;
1143  case kDOUBLE:
1144  constval.doubleval = static_cast<double>(constval.bigintval);
1145  break;
1146  case kFLOAT:
1147  constval.floatval = static_cast<float>(constval.bigintval);
1148  break;
1149  case kNUMERIC:
1150  case kDECIMAL:
1151  for (int i = 0; i < new_type_info.get_scale(); i++) {
1152  constval.bigintval *= 10;
1153  }
1154  break;
1155  default:
1156  CHECK(false);
1157  }
1158  break;
1159  case kBOOLEAN:
1160  switch (new_type_info.get_type()) {
1161  case kTINYINT:
1162  constval.tinyintval = constval.boolval ? 1 : 0;
1163  break;
1164  case kINT:
1165  constval.intval = constval.boolval ? 1 : 0;
1166  break;
1167  case kSMALLINT:
1169  break;
1170  case kBIGINT:
1171  case kTIMESTAMP:
1172  constval.bigintval = constval.boolval ? 1 : 0;
1173  break;
1174  case kDOUBLE:
1175  constval.doubleval = constval.boolval ? 1 : 0;
1176  break;
1177  case kFLOAT:
1178  constval.floatval = constval.boolval ? 1 : 0;
1179  break;
1180  case kNUMERIC:
1181  case kDECIMAL:
1182  constval.bigintval = constval.boolval ? 1 : 0;
1183  for (int i = 0; i < new_type_info.get_scale(); i++) {
1184  constval.bigintval *= 10;
1185  }
1186  break;
1187  default:
1188  CHECK(false);
1189  }
1190  break;
1191  default:
1192  CHECK(false);
1193  }
1194  type_info = new_type_info;
1195 }
int8_t tinyintval
Definition: Datum.h:71
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
int8_t boolval
Definition: Datum.h:70
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
SQLTypeInfo type_info
Definition: Analyzer.h:180
int32_t intval
Definition: Datum.h:73
float floatval
Definition: Datum.h:75
int64_t bigintval
Definition: Datum.h:74
int16_t smallintval
Definition: Datum.h:72
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:624
int64_t safeScale(T from, unsigned const scale)
Definition: Analyzer.cpp:893
#define CHECK(condition)
Definition: Logger.h:291
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:

void Constant::cast_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1197 of file Analyzer.cpp.

References constval, SQLTypeInfo::get_dimension(), SQLTypeInfo::get_type(), kTEXT, Datum::stringval, and Analyzer::Expr::type_info.

Referenced by do_cast().

1197  {
1198  std::string* s = constval.stringval;
1199  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1200  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1201  // truncate string
1202  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1203  delete s;
1204  }
1205  type_info = new_type_info;
1206 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string * stringval
Definition: Datum.h:79
Definition: sqltypes.h:79
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:393

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Constant::cast_to_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1216 of file Analyzer.cpp.

References constval, DatumToString(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_type(), kTEXT, Datum::stringval, and Analyzer::Expr::type_info.

Referenced by do_cast().

1216  {
1217  const auto str_val = DatumToString(constval, type_info);
1218  constval.stringval = new std::string(str_val);
1219  if (str_type_info.get_type() != kTEXT &&
1220  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1221  // truncate the string
1222  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1223  }
1224  type_info = str_type_info;
1225 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:460
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string * stringval
Definition: Datum.h:79
Definition: sqltypes.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< Analyzer::Expr > Constant::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 91 of file Analyzer.cpp.

References constval, SQLTypeInfo::get_type(), SQLTypeInfo::is_geometry(), is_null, SQLTypeInfo::is_string(), kARRAY, Datum::stringval, Analyzer::Expr::type_info, and value_list.

Referenced by DeepCopyVisitor::visitConstant().

91  {
92  Datum d = constval;
93  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
94  d.stringval = new std::string(*constval.stringval);
95  }
96  if (type_info.get_type() == kARRAY) {
97  return makeExpr<Constant>(type_info, is_null, value_list);
98  }
99  return makeExpr<Constant>(type_info, is_null, d);
100 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
SQLTypeInfo type_info
Definition: Analyzer.h:180
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:361
std::string * stringval
Definition: Datum.h:79
bool is_geometry() const
Definition: sqltypes.h:595
bool is_string() const
Definition: sqltypes.h:559
Definition: Datum.h:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Constant::do_cast ( const SQLTypeInfo new_type_info)
protected

Definition at line 1281 of file Analyzer.cpp.

References Datum::bigintval, cast_from_string(), cast_number(), cast_string(), cast_to_string(), CHECK, constval, DateTruncate(), DateTruncateHighPrecisionToDate(), dtDAY, DateTimeUtils::get_datetime_scaled_epoch(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_elem_type(), get_is_null(), SQLTypeInfo::get_notnull(), get_nullable_type_info(), DateTimeUtils::get_timestamp_precision_scale(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), SQLTypeInfo::is_any(), SQLTypeInfo::is_array(), SQLTypeInfo::is_boolean(), SQLTypeInfo::is_geometry(), SQLTypeInfo::is_high_precision_timestamp(), is_null, Analyzer::anonymous_namespace{Analyzer.cpp}::is_null_value(), SQLTypeInfo::is_number(), SQLTypeInfo::is_string(), SQLTypeInfo::is_time(), SQLTypeInfo::is_timestamp(), kBOOLEAN, kDATE, kTIME, kTIMESTAMP, kVARCHAR, DateTimeUtils::ScaleDown, DateTimeUtils::ScaleUp, set_null_value(), Analyzer::Expr::type_info, and value_list.

Referenced by add_cast().

1281  {
1282  if (type_info == new_type_info) {
1283  return;
1284  }
1285  if (is_null && !new_type_info.get_notnull()) {
1286  type_info = new_type_info;
1287  set_null_value();
1288  return;
1289  }
1290  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1291  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1293  type_info.get_type() == kBOOLEAN)) {
1294  cast_number(new_type_info);
1295  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1296  type_info = new_type_info;
1297  } else if (new_type_info.is_geometry() &&
1298  type_info.get_type() == new_type_info.get_type()) {
1299  type_info = new_type_info;
1300  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1301  type_info = new_type_info;
1302  } else if (new_type_info.is_string() && type_info.is_string()) {
1303  cast_string(new_type_info);
1304  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1305  cast_from_string(new_type_info);
1306  } else if (new_type_info.is_string()) {
1307  cast_to_string(new_type_info);
1308  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1309  type_info = new_type_info;
1310  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1316  : DateTruncate(dtDAY, constval.bigintval);
1317  type_info = new_type_info;
1318  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1319  new_type_info.get_type() == kTIMESTAMP) {
1320  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1321  if (dimen != new_type_info.get_dimension()) {
1322  constval.bigintval = dimen < new_type_info.get_dimension()
1326  new_type_info.get_dimension() - dimen)
1330  dimen - new_type_info.get_dimension());
1331  }
1332  type_info = new_type_info;
1333  } else if (new_type_info.is_array() && type_info.is_array()) {
1334  auto new_sub_ti = new_type_info.get_elem_type();
1335  for (auto& v : value_list) {
1336  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1337  if (!c) {
1338  throw std::runtime_error("Invalid array cast.");
1339  }
1340  c->do_cast(new_sub_ti);
1341  }
1342  type_info = new_type_info;
1343  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1344  new_type_info.is_string() || new_type_info.is_boolean())) {
1345  type_info = new_type_info;
1346  set_null_value();
1347  } else if (!is_null_value(type_info, constval) &&
1348  get_nullable_type_info(type_info) == new_type_info) {
1349  CHECK(!is_null);
1350  // relax nullability
1351  type_info = new_type_info;
1352  return;
1353  } else if (type_info.is_timestamp() && new_type_info.is_any<kTIME>()) {
1354  type_info = new_type_info;
1355  return;
1356  } else {
1357  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1358  new_type_info.get_type_name() + " not supported");
1359  }
1360 }
Definition: sqltypes.h:76
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1233
bool is_timestamp() const
Definition: sqltypes.h:1044
DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool get_is_null() const
Definition: Analyzer.h:347
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1208
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
bool is_number() const
Definition: sqltypes.h:574
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool is_time() const
Definition: sqltypes.h:577
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1197
int64_t bigintval
Definition: Datum.h:74
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:361
bool is_boolean() const
Definition: sqltypes.h:580
Definition: sqltypes.h:80
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:393
std::string get_type_name() const
Definition: sqltypes.h:482
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:922
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
#define CHECK(condition)
Definition: Logger.h:291
bool is_geometry() const
Definition: sqltypes.h:595
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:1034
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1216
bool is_any() const
Definition: sqltypes.h:556
bool is_string() const
Definition: sqltypes.h:559
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:398
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:975
bool is_array() const
Definition: sqltypes.h:583
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1482

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::list<std::shared_ptr<Analyzer::Expr> >& Analyzer::Constant::get_value_list ( ) const
inline

Definition at line 350 of file Analyzer.h.

References value_list.

Referenced by CgenState::getOrAddLiteral().

350  {
351  return value_list;
352  }
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:361

+ Here is the caller graph for this function:

bool Constant::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2334 of file Analyzer.cpp.

References constval, Analyzer::Datum_equal(), get_constval(), get_is_null(), Analyzer::Expr::get_type_info(), SQLTypeInfo::is_array(), is_null, and Analyzer::Expr::type_info.

2334  {
2335  if (typeid(rhs) != typeid(Constant)) {
2336  return false;
2337  }
2338  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2339  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2340  return false;
2341  }
2342  if (is_null && rhs_c.get_is_null()) {
2343  return true;
2344  }
2345  if (type_info.is_array()) {
2346  return false;
2347  }
2348  return Datum_equal(type_info, constval, rhs_c.get_constval());
2349 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2291
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool is_array() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

void Analyzer::Constant::set_constval ( Datum  d)
inline

Definition at line 349 of file Analyzer.h.

References constval.

349 { constval = d; }
void Constant::set_null_value ( )
protected

Definition at line 1362 of file Analyzer.cpp.

References Datum::arrayval, Datum::bigintval, Datum::boolval, CHECK, constval, Datum::doubleval, Datum::floatval, SQLTypeInfo::get_type(), Datum::intval, kARRAY, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDECIMAL, kDOUBLE, kFLOAT, kINT, 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 Analyzer::Expr::type_info.

Referenced by add_cast(), Constant(), and do_cast().

1362  {
1363  switch (type_info.get_type()) {
1364  case kBOOLEAN:
1366  break;
1367  case kTINYINT:
1369  break;
1370  case kINT:
1372  break;
1373  case kSMALLINT:
1375  break;
1376  case kBIGINT:
1377  case kNUMERIC:
1378  case kDECIMAL:
1380  break;
1381  case kTIME:
1382  case kTIMESTAMP:
1383  case kDATE:
1385  break;
1386  case kVARCHAR:
1387  case kCHAR:
1388  case kTEXT:
1389  constval.stringval = nullptr;
1390  break;
1391  case kPOINT:
1392  case kMULTIPOINT:
1393  case kLINESTRING:
1394  case kMULTILINESTRING:
1395  case kPOLYGON:
1396  case kMULTIPOLYGON:
1397  constval.stringval = nullptr;
1398  break;
1399  case kFLOAT:
1401  break;
1402  case kDOUBLE:
1404  break;
1405  case kNULLT:
1406  constval.bigintval = 0;
1407  break;
1408  case kARRAY:
1409  constval.arrayval = nullptr;
1410  break;
1411  default:
1412  CHECK(false);
1413  }
1414 }
int8_t tinyintval
Definition: Datum.h:71
#define NULL_DOUBLE
Definition: sqltypes.h:76
#define NULL_FLOAT
#define NULL_BIGINT
int8_t boolval
Definition: Datum.h:70
VarlenDatum * arrayval
Definition: Datum.h:77
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
SQLTypeInfo type_info
Definition: Analyzer.h:180
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 CHECK(condition)
Definition: Logger.h:291
#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:

std::string Constant::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2741 of file Analyzer.cpp.

References constval, DatumToString(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_type(), SQLTypeInfo::is_array(), is_null, and Analyzer::Expr::type_info.

2741  {
2742  std::string str{"(Const "};
2743  if (is_null) {
2744  str += "NULL";
2745  } else if (type_info.is_array()) {
2746  const auto& elem_ti = type_info.get_elem_type();
2747  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2748  } else {
2749  str += DatumToString(constval, type_info);
2750  }
2751  str += ") ";
2752  return str;
2753 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:460
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string toString() const override
Definition: Analyzer.cpp:2741
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:975
bool is_array() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

Member Data Documentation

const std::list<std::shared_ptr<Analyzer::Expr> > Analyzer::Constant::value_list
protected

Definition at line 361 of file Analyzer.h.

Referenced by deep_copy(), do_cast(), and get_value_list().


The documentation for this class was generated from the following files: