OmniSciDB  cde582ebc3
 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 (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 313 of file Analyzer.h.

Constructor & Destructor Documentation

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

Definition at line 315 of file Analyzer.h.

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

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

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

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

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

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

339  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:72
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:355
constexpr double n
Definition: Utm.h:38
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:182
std::string * stringval
Definition: sqltypes.h:220
bool is_geometry() const
Definition: sqltypes.h:522
bool is_string() const
Definition: sqltypes.h:510

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

1340  {
1341  if (is_null) {
1342  type_info = new_type_info;
1343  set_null_value();
1344  return shared_from_this();
1345  }
1346  if (new_type_info.get_compression() != type_info.get_compression()) {
1347  if (new_type_info.get_compression() != kENCODING_NONE) {
1348  SQLTypeInfo new_ti = new_type_info;
1349  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1351  }
1352  do_cast(new_ti);
1353  }
1354  return Expr::add_cast(new_type_info);
1355  }
1356  const auto is_integral_type =
1357  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1358  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1359  // Let the codegen phase deal with casts from date/time to a number.
1360  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1361  }
1362  do_cast(new_type_info);
1363  return shared_from_this();
1364 }
void set_compression(EncodingType c)
Definition: sqltypes.h:440
bool is_fp() const
Definition: sqltypes.h:514
Definition: sqldefs.h:48
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool is_time() const
Definition: sqltypes.h:516
bool is_integer() const
Definition: sqltypes.h:512
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1210
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:716
bool contains_agg
Definition: Analyzer.h:183
bool is_decimal() const
Definition: sqltypes.h:513
bool is_date() const
Definition: sqltypes.h:883

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1141 of file Analyzer.cpp.

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

Referenced by do_cast().

1141  {
1142  std::string* s = constval.stringval;
1143  SQLTypeInfo ti = new_type_info;
1144  constval = StringToDatum(*s, ti);
1145  delete s;
1146  type_info = new_type_info;
1147 }
SQLTypeInfo type_info
Definition: Analyzer.h:182
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 855 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().

855  {
856  switch (type_info.get_type()) {
857  case kTINYINT:
858  switch (new_type_info.get_type()) {
859  case kTINYINT:
860  break;
861  case kINT:
862  constval.intval = (int32_t)constval.tinyintval;
863  break;
864  case kSMALLINT:
866  break;
867  case kBIGINT:
868  case kTIMESTAMP:
870  break;
871  case kDOUBLE:
873  break;
874  case kFLOAT:
876  break;
877  case kNUMERIC:
878  case kDECIMAL:
880  break;
881  default:
882  CHECK(false);
883  }
884  break;
885  case kINT:
886  switch (new_type_info.get_type()) {
887  case kTINYINT:
888  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
889  break;
890  case kINT:
891  break;
892  case kSMALLINT:
893  constval.smallintval = safeNarrow<int16_t>(constval.intval);
894  break;
895  case kBIGINT:
896  case kTIMESTAMP:
897  constval.bigintval = (int64_t)constval.intval;
898  break;
899  case kDOUBLE:
900  constval.doubleval = (double)constval.intval;
901  break;
902  case kFLOAT:
903  constval.floatval = (float)constval.intval;
904  break;
905  case kNUMERIC:
906  case kDECIMAL:
907  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
908  break;
909  default:
910  CHECK(false);
911  }
912  break;
913  case kSMALLINT:
914  switch (new_type_info.get_type()) {
915  case kTINYINT:
916  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
917  break;
918  case kINT:
919  constval.intval = (int32_t)constval.smallintval;
920  break;
921  case kSMALLINT:
922  break;
923  case kBIGINT:
924  case kTIMESTAMP:
926  break;
927  case kDOUBLE:
929  break;
930  case kFLOAT:
932  break;
933  case kNUMERIC:
934  case kDECIMAL:
936  break;
937  default:
938  CHECK(false);
939  }
940  break;
941  case kBIGINT:
942  switch (new_type_info.get_type()) {
943  case kTINYINT:
944  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
945  break;
946  case kINT:
947  constval.intval = safeNarrow<int32_t>(constval.bigintval);
948  break;
949  case kSMALLINT:
950  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
951  break;
952  case kBIGINT:
953  case kTIMESTAMP:
954  break;
955  case kDOUBLE:
957  break;
958  case kFLOAT:
960  break;
961  case kNUMERIC:
962  case kDECIMAL:
964  break;
965  default:
966  CHECK(false);
967  }
968  break;
969  case kDOUBLE:
970  switch (new_type_info.get_type()) {
971  case kTINYINT:
972  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
973  break;
974  case kINT:
975  constval.intval = safeRound<int32_t>(constval.doubleval);
976  break;
977  case kSMALLINT:
978  constval.smallintval = safeRound<int16_t>(constval.doubleval);
979  break;
980  case kBIGINT:
981  case kTIMESTAMP:
982  constval.bigintval = safeRound<int64_t>(constval.doubleval);
983  break;
984  case kDOUBLE:
985  break;
986  case kFLOAT:
988  break;
989  case kNUMERIC:
990  case kDECIMAL:
992  break;
993  default:
994  CHECK(false);
995  }
996  break;
997  case kFLOAT:
998  switch (new_type_info.get_type()) {
999  case kTINYINT:
1000  constval.tinyintval = safeRound<int8_t>(constval.floatval);
1001  break;
1002  case kINT:
1003  constval.intval = safeRound<int32_t>(constval.floatval);
1004  break;
1005  case kSMALLINT:
1006  constval.smallintval = safeRound<int16_t>(constval.floatval);
1007  break;
1008  case kBIGINT:
1009  case kTIMESTAMP:
1010  constval.bigintval = safeRound<int64_t>(constval.floatval);
1011  break;
1012  case kDOUBLE:
1013  constval.doubleval = (double)constval.floatval;
1014  break;
1015  case kFLOAT:
1016  break;
1017  case kNUMERIC:
1018  case kDECIMAL:
1019  constval.bigintval = safeScale(constval.floatval, new_type_info.get_scale());
1020  break;
1021  default:
1022  CHECK(false);
1023  }
1024  break;
1025  case kNUMERIC:
1026  case kDECIMAL:
1027  switch (new_type_info.get_type()) {
1028  case kTINYINT:
1030  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1031  break;
1032  case kINT:
1033  constval.intval =
1034  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1035  break;
1036  case kSMALLINT:
1038  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1039  break;
1040  case kBIGINT:
1041  case kTIMESTAMP:
1043  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1044  break;
1045  case kDOUBLE:
1047  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1048  break;
1049  case kFLOAT:
1050  constval.floatval =
1051  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1052  break;
1053  case kNUMERIC:
1054  case kDECIMAL:
1056  constval.bigintval, type_info, new_type_info);
1057  break;
1058  default:
1059  CHECK(false);
1060  }
1061  break;
1062  case kTIMESTAMP:
1063  switch (new_type_info.get_type()) {
1064  case kTINYINT:
1065  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1066  break;
1067  case kINT:
1068  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1069  break;
1070  case kSMALLINT:
1071  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1072  break;
1073  case kBIGINT:
1074  case kTIMESTAMP:
1075  break;
1076  case kDOUBLE:
1077  constval.doubleval = static_cast<double>(constval.bigintval);
1078  break;
1079  case kFLOAT:
1080  constval.floatval = static_cast<float>(constval.bigintval);
1081  break;
1082  case kNUMERIC:
1083  case kDECIMAL:
1084  for (int i = 0; i < new_type_info.get_scale(); i++) {
1085  constval.bigintval *= 10;
1086  }
1087  break;
1088  default:
1089  CHECK(false);
1090  }
1091  break;
1092  case kBOOLEAN:
1093  switch (new_type_info.get_type()) {
1094  case kTINYINT:
1095  constval.tinyintval = constval.boolval ? 1 : 0;
1096  break;
1097  case kINT:
1098  constval.intval = constval.boolval ? 1 : 0;
1099  break;
1100  case kSMALLINT:
1102  break;
1103  case kBIGINT:
1104  case kTIMESTAMP:
1105  constval.bigintval = constval.boolval ? 1 : 0;
1106  break;
1107  case kDOUBLE:
1108  constval.doubleval = constval.boolval ? 1 : 0;
1109  break;
1110  case kFLOAT:
1111  constval.floatval = constval.boolval ? 1 : 0;
1112  break;
1113  case kNUMERIC:
1114  case kDECIMAL:
1115  constval.bigintval = constval.boolval ? 1 : 0;
1116  for (int i = 0; i < new_type_info.get_scale(); i++) {
1117  constval.bigintval *= 10;
1118  }
1119  break;
1120  default:
1121  CHECK(false);
1122  }
1123  break;
1124  default:
1125  CHECK(false);
1126  }
1127  type_info = new_type_info;
1128 }
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:182
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:556
int64_t safeScale(T from, unsigned const scale)
Definition: Analyzer.cpp:826
#define CHECK(condition)
Definition: Logger.h:222
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 1130 of file Analyzer.cpp.

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

Referenced by do_cast().

1130  {
1131  std::string* s = constval.stringval;
1132  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1133  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1134  // truncate string
1135  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1136  delete s;
1137  }
1138  type_info = new_type_info;
1139 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
SQLTypeInfo type_info
Definition: Analyzer.h:182
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 1149 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().

1149  {
1150  const auto str_val = DatumToString(constval, type_info);
1151  constval.stringval = new std::string(str_val);
1152  if (str_type_info.get_type() != kTEXT &&
1153  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1154  // truncate the string
1155  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1156  }
1157  type_info = str_type_info;
1158 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:392
SQLTypeInfo type_info
Definition: Analyzer.h:182
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 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:329
SQLTypeInfo type_info
Definition: Analyzer.h:182
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:355
std::string * stringval
Definition: sqltypes.h:220
bool is_geometry() const
Definition: sqltypes.h:522
bool is_string() const
Definition: sqltypes.h:510

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

1210  {
1211  if (type_info == new_type_info) {
1212  return;
1213  }
1214  if (is_null && !new_type_info.get_notnull()) {
1215  type_info = new_type_info;
1216  set_null_value();
1217  return;
1218  }
1219  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1220  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1222  type_info.get_type() == kBOOLEAN)) {
1223  cast_number(new_type_info);
1224  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1225  type_info = new_type_info;
1226  } else if (new_type_info.is_geometry() &&
1227  type_info.get_type() == new_type_info.get_type()) {
1228  type_info = new_type_info;
1229  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1230  type_info = new_type_info;
1231  } else if (new_type_info.is_string() && type_info.is_string()) {
1232  cast_string(new_type_info);
1233  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1234  cast_from_string(new_type_info);
1235  } else if (new_type_info.is_string()) {
1236  cast_to_string(new_type_info);
1237  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1238  type_info = new_type_info;
1239  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1245  : DateTruncate(dtDAY, constval.bigintval);
1246  type_info = new_type_info;
1247  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1248  new_type_info.get_type() == kTIMESTAMP) {
1249  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1250  if (dimen != new_type_info.get_dimension()) {
1251  constval.bigintval = dimen < new_type_info.get_dimension()
1255  new_type_info.get_dimension() - dimen)
1259  dimen - new_type_info.get_dimension());
1260  }
1261  type_info = new_type_info;
1262  } else if (new_type_info.is_array() && type_info.is_array()) {
1263  auto new_sub_ti = new_type_info.get_elem_type();
1264  for (auto& v : value_list) {
1265  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1266  if (!c) {
1267  throw std::runtime_error("Invalid array cast.");
1268  }
1269  c->do_cast(new_sub_ti);
1270  }
1271  type_info = new_type_info;
1272  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1273  new_type_info.is_string() || new_type_info.is_boolean())) {
1274  type_info = new_type_info;
1275  set_null_value();
1276  } else if (!is_null_value(type_info, constval) &&
1277  get_nullable_type_info(type_info) == new_type_info) {
1278  CHECK(!is_null);
1279  // relax nullability
1280  type_info = new_type_info;
1281  return;
1282  } else {
1283  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1284  new_type_info.get_type_name() + " not supported");
1285  }
1286 }
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1166
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool get_is_null() const
Definition: Analyzer.h:341
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1141
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
bool is_number() const
Definition: sqltypes.h:515
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool is_time() const
Definition: sqltypes.h:516
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1130
int64_t bigintval
Definition: sqltypes.h:215
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:355
bool is_boolean() const
Definition: sqltypes.h:517
Definition: sqltypes.h:53
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:331
std::string get_type_name() const
Definition: sqltypes.h:443
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:855
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
#define CHECK(condition)
Definition: Logger.h:222
bool is_geometry() const
Definition: sqltypes.h:522
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:885
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1149
bool is_string() const
Definition: sqltypes.h:510
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:865
bool is_array() const
Definition: sqltypes.h:518
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1102

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

References value_list.

Referenced by CgenState::getOrAddLiteral().

344  {
345  return value_list;
346  }
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:355

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

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

2225  {
2226  if (typeid(rhs) != typeid(Constant)) {
2227  return false;
2228  }
2229  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2230  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2231  return false;
2232  }
2233  if (is_null && rhs_c.get_is_null()) {
2234  return true;
2235  }
2236  if (type_info.is_array()) {
2237  return false;
2238  }
2239  return Datum_equal(type_info, constval, rhs_c.get_constval());
2240 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2184
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool is_array() const
Definition: sqltypes.h:518

+ Here is the call graph for this function:

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

Definition at line 343 of file Analyzer.h.

References constval.

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

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

1288  {
1289  switch (type_info.get_type()) {
1290  case kBOOLEAN:
1292  break;
1293  case kTINYINT:
1295  break;
1296  case kINT:
1298  break;
1299  case kSMALLINT:
1301  break;
1302  case kBIGINT:
1303  case kNUMERIC:
1304  case kDECIMAL:
1306  break;
1307  case kTIME:
1308  case kTIMESTAMP:
1309  case kDATE:
1311  break;
1312  case kVARCHAR:
1313  case kCHAR:
1314  case kTEXT:
1315  constval.stringval = nullptr;
1316  break;
1317  case kPOINT:
1318  case kLINESTRING:
1319  case kPOLYGON:
1320  case kMULTIPOLYGON:
1321  constval.stringval = nullptr;
1322  break;
1323  case kFLOAT:
1325  break;
1326  case kDOUBLE:
1328  break;
1329  case kNULLT:
1330  constval.bigintval = 0;
1331  break;
1332  case kARRAY:
1333  constval.arrayval = nullptr;
1334  break;
1335  default:
1336  CHECK(false);
1337  }
1338 }
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:182
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:222
#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 2586 of file Analyzer.cpp.

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

2586  {
2587  std::string str{"(Const "};
2588  if (is_null) {
2589  str += "NULL";
2590  } else if (type_info.is_array()) {
2591  const auto& elem_ti = type_info.get_elem_type();
2592  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2593  } else {
2594  str += DatumToString(constval, type_info);
2595  }
2596  str += ") ";
2597  return str;
2598 }
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:182
std::string toString() const override
Definition: Analyzer.cpp:2586
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:865
bool is_array() const
Definition: sqltypes.h:518

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