OmniSciDB  6686921089
 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 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 (bool(*f)(const Expr *), 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 305 of file Analyzer.h.

Constructor & Destructor Documentation

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

Definition at line 307 of file Analyzer.h.

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

307  : Expr(t, !n), is_null(n) {
308  if (n) {
309  set_null_value();
310  } else {
311  type_info.set_notnull(true);
312  }
313  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
SQLTypeInfo type_info
Definition: Analyzer.h:175
void set_notnull(bool n)
Definition: sqltypes.h:426
char * t
constexpr double n
Definition: Utm.h:46

+ Here is the call graph for this function:

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

Definition at line 314 of file Analyzer.h.

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

314  : Expr(t, !n), is_null(n), constval(v) {
315  if (n) {
316  set_null_value();
317  } else {
318  type_info.set_notnull(true);
319  }
320  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
SQLTypeInfo type_info
Definition: Analyzer.h:175
void set_notnull(bool n)
Definition: sqltypes.h:426
char * t
constexpr double n
Definition: Utm.h:46

+ Here is the call graph for this function:

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

Definition at line 321 of file Analyzer.h.

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

321  : Expr(ti), is_null(n), constval(v) {
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:68
SQLTypeInfo type_info
Definition: Analyzer.h:175
void set_notnull(bool n)
Definition: sqltypes.h:426
constexpr double n
Definition: Utm.h:46

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

331  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:347
constexpr double n
Definition: Utm.h:46
Constant::~Constant ( )
override

Definition at line 42 of file Analyzer.cpp.

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

42  {
43  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
44  delete constval.stringval;
45  }
46 }
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string * stringval
Definition: sqltypes.h:220
bool is_geometry() const
Definition: sqltypes.h:521
bool is_string() const
Definition: sqltypes.h:509

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

1324  {
1325  if (is_null) {
1326  type_info = new_type_info;
1327  set_null_value();
1328  return shared_from_this();
1329  }
1330  if (new_type_info.get_compression() != type_info.get_compression()) {
1331  if (new_type_info.get_compression() != kENCODING_NONE) {
1332  SQLTypeInfo new_ti = new_type_info;
1333  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1335  }
1336  do_cast(new_ti);
1337  }
1338  return Expr::add_cast(new_type_info);
1339  }
1340  const auto is_integral_type =
1341  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1342  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1343  // Let the codegen phase deal with casts from date/time to a number.
1344  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1345  }
1346  do_cast(new_type_info);
1347  return shared_from_this();
1348 }
void set_compression(EncodingType c)
Definition: sqltypes.h:429
bool is_fp() const
Definition: sqltypes.h:513
Definition: sqldefs.h:49
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool is_time() const
Definition: sqltypes.h:515
bool is_integer() const
Definition: sqltypes.h:511
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1194
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:702
bool contains_agg
Definition: Analyzer.h:176
bool is_decimal() const
Definition: sqltypes.h:512
bool is_date() const
Definition: sqltypes.h:868

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1125 of file Analyzer.cpp.

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

Referenced by do_cast().

1125  {
1126  std::string* s = constval.stringval;
1127  SQLTypeInfo ti = new_type_info;
1128  constval = StringToDatum(*s, ti);
1129  delete s;
1130  type_info = new_type_info;
1131 }
SQLTypeInfo type_info
Definition: Analyzer.h:175
Datum StringToDatum(std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:275
std::string * stringval
Definition: sqltypes.h:220

+ 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 839 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(), i, 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().

839  {
840  switch (type_info.get_type()) {
841  case kTINYINT:
842  switch (new_type_info.get_type()) {
843  case kTINYINT:
844  break;
845  case kINT:
846  constval.intval = (int32_t)constval.tinyintval;
847  break;
848  case kSMALLINT:
850  break;
851  case kBIGINT:
852  case kTIMESTAMP:
854  break;
855  case kDOUBLE:
857  break;
858  case kFLOAT:
860  break;
861  case kNUMERIC:
862  case kDECIMAL:
864  break;
865  default:
866  CHECK(false);
867  }
868  break;
869  case kINT:
870  switch (new_type_info.get_type()) {
871  case kTINYINT:
872  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
873  break;
874  case kINT:
875  break;
876  case kSMALLINT:
877  constval.smallintval = safeNarrow<int16_t>(constval.intval);
878  break;
879  case kBIGINT:
880  case kTIMESTAMP:
881  constval.bigintval = (int64_t)constval.intval;
882  break;
883  case kDOUBLE:
884  constval.doubleval = (double)constval.intval;
885  break;
886  case kFLOAT:
887  constval.floatval = (float)constval.intval;
888  break;
889  case kNUMERIC:
890  case kDECIMAL:
891  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
892  break;
893  default:
894  CHECK(false);
895  }
896  break;
897  case kSMALLINT:
898  switch (new_type_info.get_type()) {
899  case kTINYINT:
900  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
901  break;
902  case kINT:
903  constval.intval = (int32_t)constval.smallintval;
904  break;
905  case kSMALLINT:
906  break;
907  case kBIGINT:
908  case kTIMESTAMP:
910  break;
911  case kDOUBLE:
913  break;
914  case kFLOAT:
916  break;
917  case kNUMERIC:
918  case kDECIMAL:
920  break;
921  default:
922  CHECK(false);
923  }
924  break;
925  case kBIGINT:
926  switch (new_type_info.get_type()) {
927  case kTINYINT:
928  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
929  break;
930  case kINT:
931  constval.intval = safeNarrow<int32_t>(constval.bigintval);
932  break;
933  case kSMALLINT:
934  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
935  break;
936  case kBIGINT:
937  case kTIMESTAMP:
938  break;
939  case kDOUBLE:
941  break;
942  case kFLOAT:
944  break;
945  case kNUMERIC:
946  case kDECIMAL:
948  break;
949  default:
950  CHECK(false);
951  }
952  break;
953  case kDOUBLE:
954  switch (new_type_info.get_type()) {
955  case kTINYINT:
956  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
957  break;
958  case kINT:
959  constval.intval = safeRound<int32_t>(constval.doubleval);
960  break;
961  case kSMALLINT:
962  constval.smallintval = safeRound<int16_t>(constval.doubleval);
963  break;
964  case kBIGINT:
965  case kTIMESTAMP:
966  constval.bigintval = safeRound<int64_t>(constval.doubleval);
967  break;
968  case kDOUBLE:
969  break;
970  case kFLOAT:
972  break;
973  case kNUMERIC:
974  case kDECIMAL:
976  break;
977  default:
978  CHECK(false);
979  }
980  break;
981  case kFLOAT:
982  switch (new_type_info.get_type()) {
983  case kTINYINT:
984  constval.tinyintval = safeRound<int8_t>(constval.floatval);
985  break;
986  case kINT:
987  constval.intval = safeRound<int32_t>(constval.floatval);
988  break;
989  case kSMALLINT:
990  constval.smallintval = safeRound<int16_t>(constval.floatval);
991  break;
992  case kBIGINT:
993  case kTIMESTAMP:
994  constval.bigintval = safeRound<int64_t>(constval.floatval);
995  break;
996  case kDOUBLE:
998  break;
999  case kFLOAT:
1000  break;
1001  case kNUMERIC:
1002  case kDECIMAL:
1003  constval.bigintval = safeScale(constval.floatval, new_type_info.get_scale());
1004  break;
1005  default:
1006  CHECK(false);
1007  }
1008  break;
1009  case kNUMERIC:
1010  case kDECIMAL:
1011  switch (new_type_info.get_type()) {
1012  case kTINYINT:
1014  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1015  break;
1016  case kINT:
1017  constval.intval =
1018  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1019  break;
1020  case kSMALLINT:
1022  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1023  break;
1024  case kBIGINT:
1025  case kTIMESTAMP:
1027  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1028  break;
1029  case kDOUBLE:
1031  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1032  break;
1033  case kFLOAT:
1034  constval.floatval =
1035  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1036  break;
1037  case kNUMERIC:
1038  case kDECIMAL:
1040  constval.bigintval, type_info, new_type_info);
1041  break;
1042  default:
1043  CHECK(false);
1044  }
1045  break;
1046  case kTIMESTAMP:
1047  switch (new_type_info.get_type()) {
1048  case kTINYINT:
1049  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1050  break;
1051  case kINT:
1052  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1053  break;
1054  case kSMALLINT:
1055  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1056  break;
1057  case kBIGINT:
1058  case kTIMESTAMP:
1059  break;
1060  case kDOUBLE:
1061  constval.doubleval = static_cast<double>(constval.bigintval);
1062  break;
1063  case kFLOAT:
1064  constval.floatval = static_cast<float>(constval.bigintval);
1065  break;
1066  case kNUMERIC:
1067  case kDECIMAL:
1068  for (int i = 0; i < new_type_info.get_scale(); i++) {
1069  constval.bigintval *= 10;
1070  }
1071  break;
1072  default:
1073  CHECK(false);
1074  }
1075  break;
1076  case kBOOLEAN:
1077  switch (new_type_info.get_type()) {
1078  case kTINYINT:
1079  constval.tinyintval = constval.boolval ? 1 : 0;
1080  break;
1081  case kINT:
1082  constval.intval = constval.boolval ? 1 : 0;
1083  break;
1084  case kSMALLINT:
1086  break;
1087  case kBIGINT:
1088  case kTIMESTAMP:
1089  constval.bigintval = constval.boolval ? 1 : 0;
1090  break;
1091  case kDOUBLE:
1092  constval.doubleval = constval.boolval ? 1 : 0;
1093  break;
1094  case kFLOAT:
1095  constval.floatval = constval.boolval ? 1 : 0;
1096  break;
1097  case kNUMERIC:
1098  case kDECIMAL:
1099  constval.bigintval = constval.boolval ? 1 : 0;
1100  for (int i = 0; i < new_type_info.get_scale(); i++) {
1101  constval.bigintval *= 10;
1102  }
1103  break;
1104  default:
1105  CHECK(false);
1106  }
1107  break;
1108  default:
1109  CHECK(false);
1110  }
1111  type_info = new_type_info;
1112 }
int8_t tinyintval
Definition: sqltypes.h:212
HOST DEVICE int get_scale() const
Definition: sqltypes.h:334
int8_t boolval
Definition: sqltypes.h:211
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo type_info
Definition: Analyzer.h:175
int32_t intval
Definition: sqltypes.h:214
float floatval
Definition: sqltypes.h:216
int64_t bigintval
Definition: sqltypes.h:215
int16_t smallintval
Definition: sqltypes.h:213
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:473
int64_t safeScale(T from, unsigned const scale)
Definition: Analyzer.cpp:810
#define CHECK(condition)
Definition: Logger.h:209
Definition: sqltypes.h:45
double doubleval
Definition: sqltypes.h:217

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

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

Referenced by do_cast().

1114  {
1115  std::string* s = constval.stringval;
1116  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1117  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1118  // truncate string
1119  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1120  delete s;
1121  }
1122  type_info = new_type_info;
1123 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string * stringval
Definition: sqltypes.h:220
Definition: sqltypes.h:52
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331

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

1133  {
1134  const auto str_val = DatumToString(constval, type_info);
1135  constval.stringval = new std::string(str_val);
1136  if (str_type_info.get_type() != kTEXT &&
1137  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1138  // truncate the string
1139  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1140  }
1141  type_info = str_type_info;
1142 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:392
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string * stringval
Definition: sqltypes.h:220
Definition: sqltypes.h:52

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

85  {
86  Datum d = constval;
87  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
88  d.stringval = new std::string(*constval.stringval);
89  }
90  if (type_info.get_type() == kARRAY) {
91  return makeExpr<Constant>(type_info, is_null, value_list);
92  }
93  return makeExpr<Constant>(type_info, is_null, d);
94 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo type_info
Definition: Analyzer.h:175
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:347
std::string * stringval
Definition: sqltypes.h:220
bool is_geometry() const
Definition: sqltypes.h:521
bool is_string() const
Definition: sqltypes.h:509

+ 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 1194 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_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(), kBOOLEAN, kDATE, kTIMESTAMP, kVARCHAR, DateTimeUtils::ScaleDown, DateTimeUtils::ScaleUp, set_null_value(), Analyzer::Expr::type_info, and value_list.

Referenced by add_cast().

1194  {
1195  if (type_info == new_type_info) {
1196  return;
1197  }
1198  if (is_null && !new_type_info.get_notnull()) {
1199  type_info = new_type_info;
1200  set_null_value();
1201  return;
1202  }
1203  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1204  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1206  type_info.get_type() == kBOOLEAN)) {
1207  cast_number(new_type_info);
1208  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1209  type_info = new_type_info;
1210  } else if (new_type_info.is_geometry() &&
1211  type_info.get_type() == new_type_info.get_type()) {
1212  type_info = new_type_info;
1213  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1214  type_info = new_type_info;
1215  } else if (new_type_info.is_string() && type_info.is_string()) {
1216  cast_string(new_type_info);
1217  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1218  cast_from_string(new_type_info);
1219  } else if (new_type_info.is_string()) {
1220  cast_to_string(new_type_info);
1221  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1222  type_info = new_type_info;
1223  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1229  : DateTruncate(dtDAY, constval.bigintval);
1230  type_info = new_type_info;
1231  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1232  new_type_info.get_type() == kTIMESTAMP) {
1233  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1234  if (dimen != new_type_info.get_dimension()) {
1235  constval.bigintval = dimen < new_type_info.get_dimension()
1239  new_type_info.get_dimension() - dimen)
1243  dimen - new_type_info.get_dimension());
1244  }
1245  type_info = new_type_info;
1246  } else if (new_type_info.is_array() && type_info.is_array()) {
1247  auto new_sub_ti = new_type_info.get_elem_type();
1248  for (auto& v : value_list) {
1249  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1250  if (!c) {
1251  throw std::runtime_error("Invalid array cast.");
1252  }
1253  c->do_cast(new_sub_ti);
1254  }
1255  type_info = new_type_info;
1256  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1257  new_type_info.is_string() || new_type_info.is_boolean())) {
1258  type_info = new_type_info;
1259  set_null_value();
1260  } else if (!is_null_value(type_info, constval) &&
1261  get_nullable_type_info(type_info) == new_type_info) {
1262  CHECK(!is_null);
1263  // relax nullability
1264  type_info = new_type_info;
1265  return;
1266  } else {
1267  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1268  new_type_info.get_type_name() + " not supported");
1269  }
1270 }
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1150
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool get_is_null() const
Definition: Analyzer.h:333
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1125
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
bool is_number() const
Definition: sqltypes.h:514
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool is_time() const
Definition: sqltypes.h:515
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1114
int64_t bigintval
Definition: sqltypes.h:215
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:347
bool is_boolean() const
Definition: sqltypes.h:516
Definition: sqltypes.h:53
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
std::string get_type_name() const
Definition: sqltypes.h:432
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:839
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
#define CHECK(condition)
Definition: Logger.h:209
bool is_geometry() const
Definition: sqltypes.h:521
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:870
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1133
bool is_string() const
Definition: sqltypes.h:509
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:850
bool is_array() const
Definition: sqltypes.h:517
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1064

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

References value_list.

Referenced by CgenState::getOrAddLiteral().

336  {
337  return value_list;
338  }
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:347

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

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

2180  {
2181  if (typeid(rhs) != typeid(Constant)) {
2182  return false;
2183  }
2184  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2185  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2186  return false;
2187  }
2188  if (is_null && rhs_c.get_is_null()) {
2189  return true;
2190  }
2191  if (type_info.is_array()) {
2192  return false;
2193  }
2194  return Datum_equal(type_info, constval, rhs_c.get_constval());
2195 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2139
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool is_array() const
Definition: sqltypes.h:517

+ Here is the call graph for this function:

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

Definition at line 335 of file Analyzer.h.

References constval.

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

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

1272  {
1273  switch (type_info.get_type()) {
1274  case kBOOLEAN:
1276  break;
1277  case kTINYINT:
1279  break;
1280  case kINT:
1282  break;
1283  case kSMALLINT:
1285  break;
1286  case kBIGINT:
1287  case kNUMERIC:
1288  case kDECIMAL:
1290  break;
1291  case kTIME:
1292  case kTIMESTAMP:
1293  case kDATE:
1295  break;
1296  case kVARCHAR:
1297  case kCHAR:
1298  case kTEXT:
1299  constval.stringval = nullptr;
1300  break;
1301  case kPOINT:
1302  case kLINESTRING:
1303  case kPOLYGON:
1304  case kMULTIPOLYGON:
1305  constval.stringval = nullptr;
1306  break;
1307  case kFLOAT:
1309  break;
1310  case kDOUBLE:
1312  break;
1313  case kNULLT:
1314  constval.bigintval = 0;
1315  break;
1316  case kARRAY:
1317  constval.arrayval = nullptr;
1318  break;
1319  default:
1320  CHECK(false);
1321  }
1322 }
int8_t tinyintval
Definition: sqltypes.h:212
#define NULL_DOUBLE
Definition: sqltypes.h:49
#define NULL_FLOAT
#define NULL_BIGINT
int8_t boolval
Definition: sqltypes.h:211
VarlenDatum * arrayval
Definition: sqltypes.h:218
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo type_info
Definition: Analyzer.h:175
int32_t intval
Definition: sqltypes.h:214
#define NULL_INT
float floatval
Definition: sqltypes.h:216
int64_t bigintval
Definition: sqltypes.h:215
int16_t smallintval
Definition: sqltypes.h:213
#define NULL_BOOLEAN
std::string * stringval
Definition: sqltypes.h:220
Definition: sqltypes.h:52
Definition: sqltypes.h:53
Definition: sqltypes.h:41
#define NULL_TINYINT
#define CHECK(condition)
Definition: Logger.h:209
#define NULL_SMALLINT
Definition: sqltypes.h:45
double doubleval
Definition: sqltypes.h:217

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

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

2533  {
2534  std::string str{"(Const "};
2535  if (is_null) {
2536  str += "NULL";
2537  } else if (type_info.is_array()) {
2538  const auto& elem_ti = type_info.get_elem_type();
2539  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2540  } else {
2541  str += DatumToString(constval, type_info);
2542  }
2543  str += ") ";
2544  return str;
2545 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:392
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string toString() const override
Definition: Analyzer.cpp:2533
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:850
bool is_array() const
Definition: sqltypes.h:517

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