OmniSciDB  c1a53651b2
 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:500
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:500
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:500
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: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:180
std::string * stringval
Definition: Datum.h:77
bool is_geometry() const
Definition: sqltypes.h:592
bool is_string() const
Definition: sqltypes.h:580

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

1392  {
1393  if (is_null) {
1394  type_info = new_type_info;
1395  set_null_value();
1396  return shared_from_this();
1397  }
1398  if (new_type_info.get_compression() != type_info.get_compression()) {
1399  if (new_type_info.get_compression() != kENCODING_NONE) {
1400  SQLTypeInfo new_ti = new_type_info;
1401  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1403  }
1404  do_cast(new_ti);
1405  }
1406  return Expr::add_cast(new_type_info);
1407  }
1408  const auto is_integral_type =
1409  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1410  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1411  // Let the codegen phase deal with casts from date/time to a number.
1412  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1413  }
1414  do_cast(new_type_info);
1415  return shared_from_this();
1416 }
void set_compression(EncodingType c)
Definition: sqltypes.h:504
bool is_fp() const
Definition: sqltypes.h:584
Definition: sqldefs.h:48
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool is_time() const
Definition: sqltypes.h:586
bool is_integer() const
Definition: sqltypes.h:582
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1257
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:746
bool contains_agg
Definition: Analyzer.h:181
bool is_decimal() const
Definition: sqltypes.h:583
bool is_date() const
Definition: sqltypes.h:998

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1184 of file Analyzer.cpp.

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

Referenced by do_cast().

1184  {
1185  std::string* s = constval.stringval;
1186  SQLTypeInfo ti = new_type_info;
1187  constval = StringToDatum(*s, ti);
1188  delete s;
1189  type_info = new_type_info;
1190 }
SQLTypeInfo type_info
Definition: Analyzer.h:180
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 898 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().

898  {
899  switch (type_info.get_type()) {
900  case kTINYINT:
901  switch (new_type_info.get_type()) {
902  case kTINYINT:
903  break;
904  case kINT:
905  constval.intval = (int32_t)constval.tinyintval;
906  break;
907  case kSMALLINT:
909  break;
910  case kBIGINT:
911  case kTIMESTAMP:
913  break;
914  case kDOUBLE:
916  break;
917  case kFLOAT:
919  break;
920  case kNUMERIC:
921  case kDECIMAL:
923  break;
924  default:
925  CHECK(false);
926  }
927  break;
928  case kINT:
929  switch (new_type_info.get_type()) {
930  case kTINYINT:
931  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
932  break;
933  case kINT:
934  break;
935  case kSMALLINT:
936  constval.smallintval = safeNarrow<int16_t>(constval.intval);
937  break;
938  case kBIGINT:
939  case kTIMESTAMP:
940  constval.bigintval = (int64_t)constval.intval;
941  break;
942  case kDOUBLE:
943  constval.doubleval = (double)constval.intval;
944  break;
945  case kFLOAT:
946  constval.floatval = (float)constval.intval;
947  break;
948  case kNUMERIC:
949  case kDECIMAL:
950  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
951  break;
952  default:
953  CHECK(false);
954  }
955  break;
956  case kSMALLINT:
957  switch (new_type_info.get_type()) {
958  case kTINYINT:
959  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
960  break;
961  case kINT:
962  constval.intval = (int32_t)constval.smallintval;
963  break;
964  case kSMALLINT:
965  break;
966  case kBIGINT:
967  case kTIMESTAMP:
969  break;
970  case kDOUBLE:
972  break;
973  case kFLOAT:
975  break;
976  case kNUMERIC:
977  case kDECIMAL:
979  break;
980  default:
981  CHECK(false);
982  }
983  break;
984  case kBIGINT:
985  switch (new_type_info.get_type()) {
986  case kTINYINT:
987  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
988  break;
989  case kINT:
990  constval.intval = safeNarrow<int32_t>(constval.bigintval);
991  break;
992  case kSMALLINT:
993  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
994  break;
995  case kBIGINT:
996  case kTIMESTAMP:
997  break;
998  case kDOUBLE:
1000  break;
1001  case kFLOAT:
1003  break;
1004  case kNUMERIC:
1005  case kDECIMAL:
1007  break;
1008  default:
1009  CHECK(false);
1010  }
1011  break;
1012  case kDOUBLE:
1013  switch (new_type_info.get_type()) {
1014  case kTINYINT:
1015  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
1016  break;
1017  case kINT:
1018  constval.intval = safeRound<int32_t>(constval.doubleval);
1019  break;
1020  case kSMALLINT:
1021  constval.smallintval = safeRound<int16_t>(constval.doubleval);
1022  break;
1023  case kBIGINT:
1024  case kTIMESTAMP:
1025  constval.bigintval = safeRound<int64_t>(constval.doubleval);
1026  break;
1027  case kDOUBLE:
1028  break;
1029  case kFLOAT:
1031  break;
1032  case kNUMERIC:
1033  case kDECIMAL:
1035  break;
1036  default:
1037  CHECK(false);
1038  }
1039  break;
1040  case kFLOAT:
1041  switch (new_type_info.get_type()) {
1042  case kTINYINT:
1043  constval.tinyintval = safeRound<int8_t>(constval.floatval);
1044  break;
1045  case kINT:
1046  constval.intval = safeRound<int32_t>(constval.floatval);
1047  break;
1048  case kSMALLINT:
1049  constval.smallintval = safeRound<int16_t>(constval.floatval);
1050  break;
1051  case kBIGINT:
1052  case kTIMESTAMP:
1053  constval.bigintval = safeRound<int64_t>(constval.floatval);
1054  break;
1055  case kDOUBLE:
1056  constval.doubleval = (double)constval.floatval;
1057  break;
1058  case kFLOAT:
1059  break;
1060  case kNUMERIC:
1061  case kDECIMAL:
1062  constval.bigintval = safeScale(constval.floatval, new_type_info.get_scale());
1063  break;
1064  default:
1065  CHECK(false);
1066  }
1067  break;
1068  case kNUMERIC:
1069  case kDECIMAL:
1070  switch (new_type_info.get_type()) {
1071  case kTINYINT:
1073  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1074  break;
1075  case kINT:
1076  constval.intval =
1077  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1078  break;
1079  case kSMALLINT:
1081  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1082  break;
1083  case kBIGINT:
1084  case kTIMESTAMP:
1086  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1087  break;
1088  case kDOUBLE:
1090  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1091  break;
1092  case kFLOAT:
1093  constval.floatval =
1094  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1095  break;
1096  case kNUMERIC:
1097  case kDECIMAL:
1099  constval.bigintval, type_info, new_type_info);
1100  break;
1101  default:
1102  CHECK(false);
1103  }
1104  break;
1105  case kTIMESTAMP:
1106  switch (new_type_info.get_type()) {
1107  case kTINYINT:
1108  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1109  break;
1110  case kINT:
1111  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1112  break;
1113  case kSMALLINT:
1114  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1115  break;
1116  case kBIGINT:
1117  case kTIMESTAMP:
1118  break;
1119  case kDOUBLE:
1120  constval.doubleval = static_cast<double>(constval.bigintval);
1121  break;
1122  case kFLOAT:
1123  constval.floatval = static_cast<float>(constval.bigintval);
1124  break;
1125  case kNUMERIC:
1126  case kDECIMAL:
1127  for (int i = 0; i < new_type_info.get_scale(); i++) {
1128  constval.bigintval *= 10;
1129  }
1130  break;
1131  default:
1132  CHECK(false);
1133  }
1134  break;
1135  case kBOOLEAN:
1136  switch (new_type_info.get_type()) {
1137  case kTINYINT:
1138  constval.tinyintval = constval.boolval ? 1 : 0;
1139  break;
1140  case kINT:
1141  constval.intval = constval.boolval ? 1 : 0;
1142  break;
1143  case kSMALLINT:
1145  break;
1146  case kBIGINT:
1147  case kTIMESTAMP:
1148  constval.bigintval = constval.boolval ? 1 : 0;
1149  break;
1150  case kDOUBLE:
1151  constval.doubleval = constval.boolval ? 1 : 0;
1152  break;
1153  case kFLOAT:
1154  constval.floatval = constval.boolval ? 1 : 0;
1155  break;
1156  case kNUMERIC:
1157  case kDECIMAL:
1158  constval.bigintval = constval.boolval ? 1 : 0;
1159  for (int i = 0; i < new_type_info.get_scale(); i++) {
1160  constval.bigintval *= 10;
1161  }
1162  break;
1163  default:
1164  CHECK(false);
1165  }
1166  break;
1167  default:
1168  CHECK(false);
1169  }
1170  type_info = new_type_info;
1171 }
int8_t tinyintval
Definition: Datum.h:69
HOST DEVICE int get_scale() const
Definition: sqltypes.h:386
int8_t boolval
Definition: Datum.h:68
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
SQLTypeInfo type_info
Definition: Analyzer.h:180
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:869
#define CHECK(condition)
Definition: Logger.h:291
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:

void Constant::cast_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1173 of file Analyzer.cpp.

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

Referenced by do_cast().

1173  {
1174  std::string* s = constval.stringval;
1175  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1176  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1177  // truncate string
1178  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1179  delete s;
1180  }
1181  type_info = new_type_info;
1182 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string * stringval
Definition: Datum.h:77
Definition: sqltypes.h:69
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383

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

1192  {
1193  const auto str_val = DatumToString(constval, type_info);
1194  constval.stringval = new std::string(str_val);
1195  if (str_type_info.get_type() != kTEXT &&
1196  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1197  // truncate the string
1198  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1199  }
1200  type_info = str_type_info;
1201 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:458
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string * stringval
Definition: Datum.h:77
Definition: sqltypes.h:69

+ 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:381
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:77
bool is_geometry() const
Definition: sqltypes.h:592
bool is_string() const
Definition: sqltypes.h:580
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 1257 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().

1257  {
1258  if (type_info == new_type_info) {
1259  return;
1260  }
1261  if (is_null && !new_type_info.get_notnull()) {
1262  type_info = new_type_info;
1263  set_null_value();
1264  return;
1265  }
1266  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1267  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1269  type_info.get_type() == kBOOLEAN)) {
1270  cast_number(new_type_info);
1271  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1272  type_info = new_type_info;
1273  } else if (new_type_info.is_geometry() &&
1274  type_info.get_type() == new_type_info.get_type()) {
1275  type_info = new_type_info;
1276  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1277  type_info = new_type_info;
1278  } else if (new_type_info.is_string() && type_info.is_string()) {
1279  cast_string(new_type_info);
1280  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1281  cast_from_string(new_type_info);
1282  } else if (new_type_info.is_string()) {
1283  cast_to_string(new_type_info);
1284  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1285  type_info = new_type_info;
1286  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1292  : DateTruncate(dtDAY, constval.bigintval);
1293  type_info = new_type_info;
1294  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1295  new_type_info.get_type() == kTIMESTAMP) {
1296  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1297  if (dimen != new_type_info.get_dimension()) {
1298  constval.bigintval = dimen < new_type_info.get_dimension()
1302  new_type_info.get_dimension() - dimen)
1306  dimen - new_type_info.get_dimension());
1307  }
1308  type_info = new_type_info;
1309  } else if (new_type_info.is_array() && type_info.is_array()) {
1310  auto new_sub_ti = new_type_info.get_elem_type();
1311  for (auto& v : value_list) {
1312  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1313  if (!c) {
1314  throw std::runtime_error("Invalid array cast.");
1315  }
1316  c->do_cast(new_sub_ti);
1317  }
1318  type_info = new_type_info;
1319  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1320  new_type_info.is_string() || new_type_info.is_boolean())) {
1321  type_info = new_type_info;
1322  set_null_value();
1323  } else if (!is_null_value(type_info, constval) &&
1324  get_nullable_type_info(type_info) == new_type_info) {
1325  CHECK(!is_null);
1326  // relax nullability
1327  type_info = new_type_info;
1328  return;
1329  } else if (type_info.is_timestamp() && new_type_info.is_any<kTIME>()) {
1330  type_info = new_type_info;
1331  return;
1332  } else {
1333  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1334  new_type_info.get_type_name() + " not supported");
1335  }
1336 }
Definition: sqltypes.h:66
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1209
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool is_timestamp() const
Definition: sqltypes.h:1014
bool get_is_null() const
Definition: Analyzer.h:347
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1184
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
bool is_number() const
Definition: sqltypes.h:585
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:586
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1173
int64_t bigintval
Definition: Datum.h:72
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:361
bool is_boolean() const
Definition: sqltypes.h:587
Definition: sqltypes.h:70
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:383
std::string get_type_name() const
Definition: sqltypes.h:507
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:898
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:592
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:1004
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1192
bool is_any() const
Definition: sqltypes.h:577
bool is_string() const
Definition: sqltypes.h:580
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:388
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:963
bool is_array() const
Definition: sqltypes.h:588
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1247

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

2275  {
2276  if (typeid(rhs) != typeid(Constant)) {
2277  return false;
2278  }
2279  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2280  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2281  return false;
2282  }
2283  if (is_null && rhs_c.get_is_null()) {
2284  return true;
2285  }
2286  if (type_info.is_array()) {
2287  return false;
2288  }
2289  return Datum_equal(type_info, constval, rhs_c.get_constval());
2290 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2232
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool is_array() const
Definition: sqltypes.h:588

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

1338  {
1339  switch (type_info.get_type()) {
1340  case kBOOLEAN:
1342  break;
1343  case kTINYINT:
1345  break;
1346  case kINT:
1348  break;
1349  case kSMALLINT:
1351  break;
1352  case kBIGINT:
1353  case kNUMERIC:
1354  case kDECIMAL:
1356  break;
1357  case kTIME:
1358  case kTIMESTAMP:
1359  case kDATE:
1361  break;
1362  case kVARCHAR:
1363  case kCHAR:
1364  case kTEXT:
1365  constval.stringval = nullptr;
1366  break;
1367  case kPOINT:
1368  case kMULTIPOINT:
1369  case kLINESTRING:
1370  case kMULTILINESTRING:
1371  case kPOLYGON:
1372  case kMULTIPOLYGON:
1373  constval.stringval = nullptr;
1374  break;
1375  case kFLOAT:
1377  break;
1378  case kDOUBLE:
1380  break;
1381  case kNULLT:
1382  constval.bigintval = 0;
1383  break;
1384  case kARRAY:
1385  constval.arrayval = nullptr;
1386  break;
1387  default:
1388  CHECK(false);
1389  }
1390 }
int8_t tinyintval
Definition: Datum.h:69
#define NULL_DOUBLE
Definition: sqltypes.h:66
#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:381
SQLTypeInfo type_info
Definition: Analyzer.h:180
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 CHECK(condition)
Definition: Logger.h:291
#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:

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

Implements Analyzer::Expr.

Definition at line 2638 of file Analyzer.cpp.

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

2638  {
2639  std::string str{"(Const "};
2640  if (is_null) {
2641  str += "NULL";
2642  } else if (type_info.is_array()) {
2643  const auto& elem_ti = type_info.get_elem_type();
2644  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2645  } else {
2646  str += DatumToString(constval, type_info);
2647  }
2648  str += ") ";
2649  return str;
2650 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:458
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:381
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::string toString() const override
Definition: Analyzer.cpp:2638
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:963
bool is_array() const
Definition: sqltypes.h:588

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