OmniSciDB  a987f07e93
 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 315 of file Analyzer.h.

Constructor & Destructor Documentation

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

Definition at line 317 of file Analyzer.h.

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

317  : Expr(t, !n), is_null(n) {
318  if (n) {
319  set_null_value();
320  } else {
321  type_info.set_notnull(true);
322  }
323  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
SQLTypeInfo type_info
Definition: Analyzer.h:184
void set_notnull(bool n)
Definition: sqltypes.h:497
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 324 of file Analyzer.h.

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

324  : Expr(t, !n), is_null(n), constval(v) {
325  if (n) {
326  set_null_value();
327  } else {
328  type_info.set_notnull(true);
329  }
330  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
SQLTypeInfo type_info
Definition: Analyzer.h:184
void set_notnull(bool n)
Definition: sqltypes.h:497
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 331 of file Analyzer.h.

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

331  : Expr(ti), is_null(n), constval(v) {
332  if (n) {
333  set_null_value();
334  } else {
335  type_info.set_notnull(true);
336  }
337  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
SQLTypeInfo type_info
Definition: Analyzer.h:184
void set_notnull(bool n)
Definition: sqltypes.h:497
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 338 of file Analyzer.h.

341  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:357
constexpr double n
Definition: Utm.h:38
Definition: Datum.h:67
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:184
std::string * stringval
Definition: Datum.h:77
bool is_geometry() const
Definition: sqltypes.h:588
bool is_string() const
Definition: sqltypes.h:576

+ 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 1375 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.

1375  {
1376  if (is_null) {
1377  type_info = new_type_info;
1378  set_null_value();
1379  return shared_from_this();
1380  }
1381  if (new_type_info.get_compression() != type_info.get_compression()) {
1382  if (new_type_info.get_compression() != kENCODING_NONE) {
1383  SQLTypeInfo new_ti = new_type_info;
1384  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1386  }
1387  do_cast(new_ti);
1388  }
1389  return Expr::add_cast(new_type_info);
1390  }
1391  const auto is_integral_type =
1392  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1393  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1394  // Let the codegen phase deal with casts from date/time to a number.
1395  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1396  }
1397  do_cast(new_type_info);
1398  return shared_from_this();
1399 }
void set_compression(EncodingType c)
Definition: sqltypes.h:501
bool is_fp() const
Definition: sqltypes.h:580
Definition: sqldefs.h:48
SQLTypeInfo type_info
Definition: Analyzer.h:184
bool is_time() const
Definition: sqltypes.h:582
bool is_integer() const
Definition: sqltypes.h:578
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1240
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:388
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:728
bool contains_agg
Definition: Analyzer.h:185
bool is_decimal() const
Definition: sqltypes.h:579
bool is_date() const
Definition: sqltypes.h:984

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1167 of file Analyzer.cpp.

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

Referenced by do_cast().

1167  {
1168  std::string* s = constval.stringval;
1169  SQLTypeInfo ti = new_type_info;
1170  constval = StringToDatum(*s, ti);
1171  delete s;
1172  type_info = new_type_info;
1173 }
SQLTypeInfo type_info
Definition: Analyzer.h:184
Datum StringToDatum(const std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:337
std::string * stringval
Definition: Datum.h:77

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

881  {
882  switch (type_info.get_type()) {
883  case kTINYINT:
884  switch (new_type_info.get_type()) {
885  case kTINYINT:
886  break;
887  case kINT:
888  constval.intval = (int32_t)constval.tinyintval;
889  break;
890  case kSMALLINT:
892  break;
893  case kBIGINT:
894  case kTIMESTAMP:
896  break;
897  case kDOUBLE:
899  break;
900  case kFLOAT:
902  break;
903  case kNUMERIC:
904  case kDECIMAL:
906  break;
907  default:
908  CHECK(false);
909  }
910  break;
911  case kINT:
912  switch (new_type_info.get_type()) {
913  case kTINYINT:
914  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
915  break;
916  case kINT:
917  break;
918  case kSMALLINT:
919  constval.smallintval = safeNarrow<int16_t>(constval.intval);
920  break;
921  case kBIGINT:
922  case kTIMESTAMP:
923  constval.bigintval = (int64_t)constval.intval;
924  break;
925  case kDOUBLE:
926  constval.doubleval = (double)constval.intval;
927  break;
928  case kFLOAT:
929  constval.floatval = (float)constval.intval;
930  break;
931  case kNUMERIC:
932  case kDECIMAL:
933  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
934  break;
935  default:
936  CHECK(false);
937  }
938  break;
939  case kSMALLINT:
940  switch (new_type_info.get_type()) {
941  case kTINYINT:
942  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
943  break;
944  case kINT:
945  constval.intval = (int32_t)constval.smallintval;
946  break;
947  case kSMALLINT:
948  break;
949  case kBIGINT:
950  case kTIMESTAMP:
952  break;
953  case kDOUBLE:
955  break;
956  case kFLOAT:
958  break;
959  case kNUMERIC:
960  case kDECIMAL:
962  break;
963  default:
964  CHECK(false);
965  }
966  break;
967  case kBIGINT:
968  switch (new_type_info.get_type()) {
969  case kTINYINT:
970  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
971  break;
972  case kINT:
973  constval.intval = safeNarrow<int32_t>(constval.bigintval);
974  break;
975  case kSMALLINT:
976  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
977  break;
978  case kBIGINT:
979  case kTIMESTAMP:
980  break;
981  case kDOUBLE:
983  break;
984  case kFLOAT:
986  break;
987  case kNUMERIC:
988  case kDECIMAL:
990  break;
991  default:
992  CHECK(false);
993  }
994  break;
995  case kDOUBLE:
996  switch (new_type_info.get_type()) {
997  case kTINYINT:
998  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
999  break;
1000  case kINT:
1001  constval.intval = safeRound<int32_t>(constval.doubleval);
1002  break;
1003  case kSMALLINT:
1004  constval.smallintval = safeRound<int16_t>(constval.doubleval);
1005  break;
1006  case kBIGINT:
1007  case kTIMESTAMP:
1008  constval.bigintval = safeRound<int64_t>(constval.doubleval);
1009  break;
1010  case kDOUBLE:
1011  break;
1012  case kFLOAT:
1014  break;
1015  case kNUMERIC:
1016  case kDECIMAL:
1018  break;
1019  default:
1020  CHECK(false);
1021  }
1022  break;
1023  case kFLOAT:
1024  switch (new_type_info.get_type()) {
1025  case kTINYINT:
1026  constval.tinyintval = safeRound<int8_t>(constval.floatval);
1027  break;
1028  case kINT:
1029  constval.intval = safeRound<int32_t>(constval.floatval);
1030  break;
1031  case kSMALLINT:
1032  constval.smallintval = safeRound<int16_t>(constval.floatval);
1033  break;
1034  case kBIGINT:
1035  case kTIMESTAMP:
1036  constval.bigintval = safeRound<int64_t>(constval.floatval);
1037  break;
1038  case kDOUBLE:
1039  constval.doubleval = (double)constval.floatval;
1040  break;
1041  case kFLOAT:
1042  break;
1043  case kNUMERIC:
1044  case kDECIMAL:
1045  constval.bigintval = safeScale(constval.floatval, new_type_info.get_scale());
1046  break;
1047  default:
1048  CHECK(false);
1049  }
1050  break;
1051  case kNUMERIC:
1052  case kDECIMAL:
1053  switch (new_type_info.get_type()) {
1054  case kTINYINT:
1056  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1057  break;
1058  case kINT:
1059  constval.intval =
1060  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1061  break;
1062  case kSMALLINT:
1064  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1065  break;
1066  case kBIGINT:
1067  case kTIMESTAMP:
1069  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1070  break;
1071  case kDOUBLE:
1073  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1074  break;
1075  case kFLOAT:
1076  constval.floatval =
1077  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1078  break;
1079  case kNUMERIC:
1080  case kDECIMAL:
1082  constval.bigintval, type_info, new_type_info);
1083  break;
1084  default:
1085  CHECK(false);
1086  }
1087  break;
1088  case kTIMESTAMP:
1089  switch (new_type_info.get_type()) {
1090  case kTINYINT:
1091  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1092  break;
1093  case kINT:
1094  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1095  break;
1096  case kSMALLINT:
1097  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1098  break;
1099  case kBIGINT:
1100  case kTIMESTAMP:
1101  break;
1102  case kDOUBLE:
1103  constval.doubleval = static_cast<double>(constval.bigintval);
1104  break;
1105  case kFLOAT:
1106  constval.floatval = static_cast<float>(constval.bigintval);
1107  break;
1108  case kNUMERIC:
1109  case kDECIMAL:
1110  for (int i = 0; i < new_type_info.get_scale(); i++) {
1111  constval.bigintval *= 10;
1112  }
1113  break;
1114  default:
1115  CHECK(false);
1116  }
1117  break;
1118  case kBOOLEAN:
1119  switch (new_type_info.get_type()) {
1120  case kTINYINT:
1121  constval.tinyintval = constval.boolval ? 1 : 0;
1122  break;
1123  case kINT:
1124  constval.intval = constval.boolval ? 1 : 0;
1125  break;
1126  case kSMALLINT:
1128  break;
1129  case kBIGINT:
1130  case kTIMESTAMP:
1131  constval.bigintval = constval.boolval ? 1 : 0;
1132  break;
1133  case kDOUBLE:
1134  constval.doubleval = constval.boolval ? 1 : 0;
1135  break;
1136  case kFLOAT:
1137  constval.floatval = constval.boolval ? 1 : 0;
1138  break;
1139  case kNUMERIC:
1140  case kDECIMAL:
1141  constval.bigintval = constval.boolval ? 1 : 0;
1142  for (int i = 0; i < new_type_info.get_scale(); i++) {
1143  constval.bigintval *= 10;
1144  }
1145  break;
1146  default:
1147  CHECK(false);
1148  }
1149  break;
1150  default:
1151  CHECK(false);
1152  }
1153  type_info = new_type_info;
1154 }
int8_t tinyintval
Definition: Datum.h:69
HOST DEVICE int get_scale() const
Definition: sqltypes.h:385
int8_t boolval
Definition: Datum.h:68
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
SQLTypeInfo type_info
Definition: Analyzer.h:184
int32_t intval
Definition: Datum.h:71
float floatval
Definition: Datum.h:73
int64_t bigintval
Definition: Datum.h:72
int16_t smallintval
Definition: Datum.h:70
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:622
int64_t safeScale(T from, unsigned const scale)
Definition: Analyzer.cpp:852
#define CHECK(condition)
Definition: Logger.h:289
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:

void Constant::cast_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1156 of file Analyzer.cpp.

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

Referenced by do_cast().

1156  {
1157  std::string* s = constval.stringval;
1158  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1159  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1160  // truncate string
1161  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1162  delete s;
1163  }
1164  type_info = new_type_info;
1165 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
SQLTypeInfo type_info
Definition: Analyzer.h:184
std::string * stringval
Definition: Datum.h:77
Definition: sqltypes.h:67
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:382

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

1175  {
1176  const auto str_val = DatumToString(constval, type_info);
1177  constval.stringval = new std::string(str_val);
1178  if (str_type_info.get_type() != kTEXT &&
1179  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1180  // truncate the string
1181  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1182  }
1183  type_info = str_type_info;
1184 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:458
SQLTypeInfo type_info
Definition: Analyzer.h:184
std::string * stringval
Definition: Datum.h:77
Definition: sqltypes.h:67

+ 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:380
SQLTypeInfo type_info
Definition: Analyzer.h:184
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:357
std::string * stringval
Definition: Datum.h:77
bool is_geometry() const
Definition: sqltypes.h:588
bool is_string() const
Definition: sqltypes.h:576
Definition: Datum.h:67

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

1240  {
1241  if (type_info == new_type_info) {
1242  return;
1243  }
1244  if (is_null && !new_type_info.get_notnull()) {
1245  type_info = new_type_info;
1246  set_null_value();
1247  return;
1248  }
1249  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1250  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1252  type_info.get_type() == kBOOLEAN)) {
1253  cast_number(new_type_info);
1254  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1255  type_info = new_type_info;
1256  } else if (new_type_info.is_geometry() &&
1257  type_info.get_type() == new_type_info.get_type()) {
1258  type_info = new_type_info;
1259  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1260  type_info = new_type_info;
1261  } else if (new_type_info.is_string() && type_info.is_string()) {
1262  cast_string(new_type_info);
1263  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1264  cast_from_string(new_type_info);
1265  } else if (new_type_info.is_string()) {
1266  cast_to_string(new_type_info);
1267  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1268  type_info = new_type_info;
1269  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1275  : DateTruncate(dtDAY, constval.bigintval);
1276  type_info = new_type_info;
1277  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1278  new_type_info.get_type() == kTIMESTAMP) {
1279  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1280  if (dimen != new_type_info.get_dimension()) {
1281  constval.bigintval = dimen < new_type_info.get_dimension()
1285  new_type_info.get_dimension() - dimen)
1289  dimen - new_type_info.get_dimension());
1290  }
1291  type_info = new_type_info;
1292  } else if (new_type_info.is_array() && type_info.is_array()) {
1293  auto new_sub_ti = new_type_info.get_elem_type();
1294  for (auto& v : value_list) {
1295  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1296  if (!c) {
1297  throw std::runtime_error("Invalid array cast.");
1298  }
1299  c->do_cast(new_sub_ti);
1300  }
1301  type_info = new_type_info;
1302  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1303  new_type_info.is_string() || new_type_info.is_boolean())) {
1304  type_info = new_type_info;
1305  set_null_value();
1306  } else if (!is_null_value(type_info, constval) &&
1307  get_nullable_type_info(type_info) == new_type_info) {
1308  CHECK(!is_null);
1309  // relax nullability
1310  type_info = new_type_info;
1311  return;
1312  } else if (type_info.is_timestamp() && new_type_info.is_any<kTIME>()) {
1313  type_info = new_type_info;
1314  return;
1315  } else {
1316  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1317  new_type_info.get_type_name() + " not supported");
1318  }
1319 }
Definition: sqltypes.h:64
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1192
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool is_timestamp() const
Definition: sqltypes.h:1000
bool get_is_null() const
Definition: Analyzer.h:343
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1167
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
bool is_number() const
Definition: sqltypes.h:581
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:184
bool is_time() const
Definition: sqltypes.h:582
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1156
int64_t bigintval
Definition: Datum.h:72
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:357
bool is_boolean() const
Definition: sqltypes.h:583
Definition: sqltypes.h:68
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:382
std::string get_type_name() const
Definition: sqltypes.h:504
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:881
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
#define CHECK(condition)
Definition: Logger.h:289
bool is_geometry() const
Definition: sqltypes.h:588
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:990
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1175
bool is_any() const
Definition: sqltypes.h:573
bool is_string() const
Definition: sqltypes.h:576
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:387
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:957
bool is_array() const
Definition: sqltypes.h:584
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1221

+ 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 346 of file Analyzer.h.

References value_list.

Referenced by CgenState::getOrAddLiteral().

346  {
347  return value_list;
348  }
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:357

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2262 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.

2262  {
2263  if (typeid(rhs) != typeid(Constant)) {
2264  return false;
2265  }
2266  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2267  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2268  return false;
2269  }
2270  if (is_null && rhs_c.get_is_null()) {
2271  return true;
2272  }
2273  if (type_info.is_array()) {
2274  return false;
2275  }
2276  return Datum_equal(type_info, constval, rhs_c.get_constval());
2277 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2219
SQLTypeInfo type_info
Definition: Analyzer.h:184
bool is_array() const
Definition: sqltypes.h:584

+ Here is the call graph for this function:

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

Definition at line 345 of file Analyzer.h.

References constval.

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

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

1321  {
1322  switch (type_info.get_type()) {
1323  case kBOOLEAN:
1325  break;
1326  case kTINYINT:
1328  break;
1329  case kINT:
1331  break;
1332  case kSMALLINT:
1334  break;
1335  case kBIGINT:
1336  case kNUMERIC:
1337  case kDECIMAL:
1339  break;
1340  case kTIME:
1341  case kTIMESTAMP:
1342  case kDATE:
1344  break;
1345  case kVARCHAR:
1346  case kCHAR:
1347  case kTEXT:
1348  constval.stringval = nullptr;
1349  break;
1350  case kPOINT:
1351  case kMULTIPOINT:
1352  case kLINESTRING:
1353  case kMULTILINESTRING:
1354  case kPOLYGON:
1355  case kMULTIPOLYGON:
1356  constval.stringval = nullptr;
1357  break;
1358  case kFLOAT:
1360  break;
1361  case kDOUBLE:
1363  break;
1364  case kNULLT:
1365  constval.bigintval = 0;
1366  break;
1367  case kARRAY:
1368  constval.arrayval = nullptr;
1369  break;
1370  default:
1371  CHECK(false);
1372  }
1373 }
int8_t tinyintval
Definition: Datum.h:69
#define NULL_DOUBLE
Definition: sqltypes.h:64
#define NULL_FLOAT
#define NULL_BIGINT
int8_t boolval
Definition: Datum.h:68
VarlenDatum * arrayval
Definition: Datum.h:75
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
SQLTypeInfo type_info
Definition: Analyzer.h:184
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 CHECK(condition)
Definition: Logger.h:289
#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:

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

Implements Analyzer::Expr.

Definition at line 2623 of file Analyzer.cpp.

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

2623  {
2624  std::string str{"(Const "};
2625  if (is_null) {
2626  str += "NULL";
2627  } else if (type_info.is_array()) {
2628  const auto& elem_ti = type_info.get_elem_type();
2629  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2630  } else {
2631  str += DatumToString(constval, type_info);
2632  }
2633  str += ") ";
2634  return str;
2635 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:458
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
SQLTypeInfo type_info
Definition: Analyzer.h:184
std::string toString() const override
Definition: Analyzer.cpp:2623
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:957
bool is_array() const
Definition: sqltypes.h:584

+ 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 357 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: