OmniSciDB  c0231cc57d
 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 314 of file Analyzer.h.

Constructor & Destructor Documentation

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

Definition at line 316 of file Analyzer.h.

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

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

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

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

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

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

340  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:356
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:183
std::string * stringval
Definition: sqltypes.h:240
bool is_geometry() const
Definition: sqltypes.h:612
bool is_string() const
Definition: sqltypes.h:600

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

1359  {
1360  if (is_null) {
1361  type_info = new_type_info;
1362  set_null_value();
1363  return shared_from_this();
1364  }
1365  if (new_type_info.get_compression() != type_info.get_compression()) {
1366  if (new_type_info.get_compression() != kENCODING_NONE) {
1367  SQLTypeInfo new_ti = new_type_info;
1368  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1370  }
1371  do_cast(new_ti);
1372  }
1373  return Expr::add_cast(new_type_info);
1374  }
1375  const auto is_integral_type =
1376  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1377  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1378  // Let the codegen phase deal with casts from date/time to a number.
1379  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1380  }
1381  do_cast(new_type_info);
1382  return shared_from_this();
1383 }
void set_compression(EncodingType c)
Definition: sqltypes.h:525
bool is_fp() const
Definition: sqltypes.h:604
Definition: sqldefs.h:48
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool is_time() const
Definition: sqltypes.h:606
bool is_integer() const
Definition: sqltypes.h:602
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1224
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:412
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:728
bool contains_agg
Definition: Analyzer.h:184
bool is_decimal() const
Definition: sqltypes.h:603
bool is_date() const
Definition: sqltypes.h:1008

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1153 of file Analyzer.cpp.

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

Referenced by do_cast().

1153  {
1154  std::string* s = constval.stringval;
1155  SQLTypeInfo ti = new_type_info;
1156  constval = StringToDatum(*s, ti);
1157  delete s;
1158  type_info = new_type_info;
1159 }
SQLTypeInfo type_info
Definition: Analyzer.h:183
Datum StringToDatum(std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:277
std::string * stringval
Definition: sqltypes.h:240

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

867  {
868  switch (type_info.get_type()) {
869  case kTINYINT:
870  switch (new_type_info.get_type()) {
871  case kTINYINT:
872  break;
873  case kINT:
874  constval.intval = (int32_t)constval.tinyintval;
875  break;
876  case kSMALLINT:
878  break;
879  case kBIGINT:
880  case kTIMESTAMP:
882  break;
883  case kDOUBLE:
885  break;
886  case kFLOAT:
888  break;
889  case kNUMERIC:
890  case kDECIMAL:
892  break;
893  default:
894  CHECK(false);
895  }
896  break;
897  case kINT:
898  switch (new_type_info.get_type()) {
899  case kTINYINT:
900  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
901  break;
902  case kINT:
903  break;
904  case kSMALLINT:
905  constval.smallintval = safeNarrow<int16_t>(constval.intval);
906  break;
907  case kBIGINT:
908  case kTIMESTAMP:
909  constval.bigintval = (int64_t)constval.intval;
910  break;
911  case kDOUBLE:
912  constval.doubleval = (double)constval.intval;
913  break;
914  case kFLOAT:
915  constval.floatval = (float)constval.intval;
916  break;
917  case kNUMERIC:
918  case kDECIMAL:
919  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
920  break;
921  default:
922  CHECK(false);
923  }
924  break;
925  case kSMALLINT:
926  switch (new_type_info.get_type()) {
927  case kTINYINT:
928  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
929  break;
930  case kINT:
931  constval.intval = (int32_t)constval.smallintval;
932  break;
933  case kSMALLINT:
934  break;
935  case kBIGINT:
936  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 kBIGINT:
954  switch (new_type_info.get_type()) {
955  case kTINYINT:
956  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
957  break;
958  case kINT:
959  constval.intval = safeNarrow<int32_t>(constval.bigintval);
960  break;
961  case kSMALLINT:
962  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
963  break;
964  case kBIGINT:
965  case kTIMESTAMP:
966  break;
967  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 kDOUBLE:
982  switch (new_type_info.get_type()) {
983  case kTINYINT:
984  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
985  break;
986  case kINT:
987  constval.intval = safeRound<int32_t>(constval.doubleval);
988  break;
989  case kSMALLINT:
990  constval.smallintval = safeRound<int16_t>(constval.doubleval);
991  break;
992  case kBIGINT:
993  case kTIMESTAMP:
994  constval.bigintval = safeRound<int64_t>(constval.doubleval);
995  break;
996  case kDOUBLE:
997  break;
998  case kFLOAT:
1000  break;
1001  case kNUMERIC:
1002  case kDECIMAL:
1004  break;
1005  default:
1006  CHECK(false);
1007  }
1008  break;
1009  case kFLOAT:
1010  switch (new_type_info.get_type()) {
1011  case kTINYINT:
1012  constval.tinyintval = safeRound<int8_t>(constval.floatval);
1013  break;
1014  case kINT:
1015  constval.intval = safeRound<int32_t>(constval.floatval);
1016  break;
1017  case kSMALLINT:
1018  constval.smallintval = safeRound<int16_t>(constval.floatval);
1019  break;
1020  case kBIGINT:
1021  case kTIMESTAMP:
1022  constval.bigintval = safeRound<int64_t>(constval.floatval);
1023  break;
1024  case kDOUBLE:
1025  constval.doubleval = (double)constval.floatval;
1026  break;
1027  case kFLOAT:
1028  break;
1029  case kNUMERIC:
1030  case kDECIMAL:
1031  constval.bigintval = safeScale(constval.floatval, new_type_info.get_scale());
1032  break;
1033  default:
1034  CHECK(false);
1035  }
1036  break;
1037  case kNUMERIC:
1038  case kDECIMAL:
1039  switch (new_type_info.get_type()) {
1040  case kTINYINT:
1042  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1043  break;
1044  case kINT:
1045  constval.intval =
1046  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1047  break;
1048  case kSMALLINT:
1050  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1051  break;
1052  case kBIGINT:
1053  case kTIMESTAMP:
1055  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1056  break;
1057  case kDOUBLE:
1059  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1060  break;
1061  case kFLOAT:
1062  constval.floatval =
1063  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1064  break;
1065  case kNUMERIC:
1066  case kDECIMAL:
1068  constval.bigintval, type_info, new_type_info);
1069  break;
1070  default:
1071  CHECK(false);
1072  }
1073  break;
1074  case kTIMESTAMP:
1075  switch (new_type_info.get_type()) {
1076  case kTINYINT:
1077  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1078  break;
1079  case kINT:
1080  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1081  break;
1082  case kSMALLINT:
1083  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1084  break;
1085  case kBIGINT:
1086  case kTIMESTAMP:
1087  break;
1088  case kDOUBLE:
1089  constval.doubleval = static_cast<double>(constval.bigintval);
1090  break;
1091  case kFLOAT:
1092  constval.floatval = static_cast<float>(constval.bigintval);
1093  break;
1094  case kNUMERIC:
1095  case kDECIMAL:
1096  for (int i = 0; i < new_type_info.get_scale(); i++) {
1097  constval.bigintval *= 10;
1098  }
1099  break;
1100  default:
1101  CHECK(false);
1102  }
1103  break;
1104  case kBOOLEAN:
1105  switch (new_type_info.get_type()) {
1106  case kTINYINT:
1107  constval.tinyintval = constval.boolval ? 1 : 0;
1108  break;
1109  case kINT:
1110  constval.intval = constval.boolval ? 1 : 0;
1111  break;
1112  case kSMALLINT:
1114  break;
1115  case kBIGINT:
1116  case kTIMESTAMP:
1117  constval.bigintval = constval.boolval ? 1 : 0;
1118  break;
1119  case kDOUBLE:
1120  constval.doubleval = constval.boolval ? 1 : 0;
1121  break;
1122  case kFLOAT:
1123  constval.floatval = constval.boolval ? 1 : 0;
1124  break;
1125  case kNUMERIC:
1126  case kDECIMAL:
1127  constval.bigintval = constval.boolval ? 1 : 0;
1128  for (int i = 0; i < new_type_info.get_scale(); i++) {
1129  constval.bigintval *= 10;
1130  }
1131  break;
1132  default:
1133  CHECK(false);
1134  }
1135  break;
1136  default:
1137  CHECK(false);
1138  }
1139  type_info = new_type_info;
1140 }
int8_t tinyintval
Definition: sqltypes.h:232
HOST DEVICE int get_scale() const
Definition: sqltypes.h:409
int8_t boolval
Definition: sqltypes.h:231
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
SQLTypeInfo type_info
Definition: Analyzer.h:183
int32_t intval
Definition: sqltypes.h:234
float floatval
Definition: sqltypes.h:236
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:562
int64_t safeScale(T from, unsigned const scale)
Definition: Analyzer.cpp:838
#define CHECK(condition)
Definition: Logger.h:222
Definition: sqltypes.h:59
double doubleval
Definition: sqltypes.h:237

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

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

Referenced by do_cast().

1142  {
1143  std::string* s = constval.stringval;
1144  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1145  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1146  // truncate string
1147  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1148  delete s;
1149  }
1150  type_info = new_type_info;
1151 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
SQLTypeInfo type_info
Definition: Analyzer.h:183
std::string * stringval
Definition: sqltypes.h:240
Definition: sqltypes.h:66
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:406

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

1161  {
1162  const auto str_val = DatumToString(constval, type_info);
1163  constval.stringval = new std::string(str_val);
1164  if (str_type_info.get_type() != kTEXT &&
1165  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1166  // truncate the string
1167  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1168  }
1169  type_info = str_type_info;
1170 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:398
SQLTypeInfo type_info
Definition: Analyzer.h:183
std::string * stringval
Definition: sqltypes.h:240
Definition: sqltypes.h:66

+ 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:404
SQLTypeInfo type_info
Definition: Analyzer.h:183
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:356
std::string * stringval
Definition: sqltypes.h:240
bool is_geometry() const
Definition: sqltypes.h:612
bool is_string() const
Definition: sqltypes.h:600

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

1224  {
1225  if (type_info == new_type_info) {
1226  return;
1227  }
1228  if (is_null && !new_type_info.get_notnull()) {
1229  type_info = new_type_info;
1230  set_null_value();
1231  return;
1232  }
1233  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1234  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1236  type_info.get_type() == kBOOLEAN)) {
1237  cast_number(new_type_info);
1238  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1239  type_info = new_type_info;
1240  } else if (new_type_info.is_geometry() &&
1241  type_info.get_type() == new_type_info.get_type()) {
1242  type_info = new_type_info;
1243  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1244  type_info = new_type_info;
1245  } else if (new_type_info.is_string() && type_info.is_string()) {
1246  cast_string(new_type_info);
1247  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1248  cast_from_string(new_type_info);
1249  } else if (new_type_info.is_string()) {
1250  cast_to_string(new_type_info);
1251  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1252  type_info = new_type_info;
1253  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1259  : DateTruncate(dtDAY, constval.bigintval);
1260  type_info = new_type_info;
1261  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1262  new_type_info.get_type() == kTIMESTAMP) {
1263  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1264  if (dimen != new_type_info.get_dimension()) {
1265  constval.bigintval = dimen < new_type_info.get_dimension()
1269  new_type_info.get_dimension() - dimen)
1273  dimen - new_type_info.get_dimension());
1274  }
1275  type_info = new_type_info;
1276  } else if (new_type_info.is_array() && type_info.is_array()) {
1277  auto new_sub_ti = new_type_info.get_elem_type();
1278  for (auto& v : value_list) {
1279  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1280  if (!c) {
1281  throw std::runtime_error("Invalid array cast.");
1282  }
1283  c->do_cast(new_sub_ti);
1284  }
1285  type_info = new_type_info;
1286  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1287  new_type_info.is_string() || new_type_info.is_boolean())) {
1288  type_info = new_type_info;
1289  set_null_value();
1290  } else if (!is_null_value(type_info, constval) &&
1291  get_nullable_type_info(type_info) == new_type_info) {
1292  CHECK(!is_null);
1293  // relax nullability
1294  type_info = new_type_info;
1295  return;
1296  } else if (type_info.is_timestamp() && new_type_info.is_any(kTIME)) {
1297  type_info = new_type_info;
1298  return;
1299  } else {
1300  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1301  new_type_info.get_type_name() + " not supported");
1302  }
1303 }
Definition: sqltypes.h:63
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1178
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool is_timestamp() const
Definition: sqltypes.h:1020
bool is_any(Types...types) const
Definition: sqltypes.h:597
bool get_is_null() const
Definition: Analyzer.h:342
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1153
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
bool is_number() const
Definition: sqltypes.h:605
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool is_time() const
Definition: sqltypes.h:606
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1142
int64_t bigintval
Definition: sqltypes.h:235
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:356
bool is_boolean() const
Definition: sqltypes.h:607
Definition: sqltypes.h:67
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:406
std::string get_type_name() const
Definition: sqltypes.h:528
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:867
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:612
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:1010
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1161
bool is_string() const
Definition: sqltypes.h:600
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:411
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:981
bool is_array() const
Definition: sqltypes.h:608
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:1236

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

References value_list.

Referenced by CgenState::getOrAddLiteral().

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

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

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

2246  {
2247  if (typeid(rhs) != typeid(Constant)) {
2248  return false;
2249  }
2250  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2251  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2252  return false;
2253  }
2254  if (is_null && rhs_c.get_is_null()) {
2255  return true;
2256  }
2257  if (type_info.is_array()) {
2258  return false;
2259  }
2260  return Datum_equal(type_info, constval, rhs_c.get_constval());
2261 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2203
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool is_array() const
Definition: sqltypes.h:608

+ Here is the call graph for this function:

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

Definition at line 344 of file Analyzer.h.

References constval.

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

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

1305  {
1306  switch (type_info.get_type()) {
1307  case kBOOLEAN:
1309  break;
1310  case kTINYINT:
1312  break;
1313  case kINT:
1315  break;
1316  case kSMALLINT:
1318  break;
1319  case kBIGINT:
1320  case kNUMERIC:
1321  case kDECIMAL:
1323  break;
1324  case kTIME:
1325  case kTIMESTAMP:
1326  case kDATE:
1328  break;
1329  case kVARCHAR:
1330  case kCHAR:
1331  case kTEXT:
1332  constval.stringval = nullptr;
1333  break;
1334  case kPOINT:
1335  case kMULTIPOINT:
1336  case kLINESTRING:
1337  case kMULTILINESTRING:
1338  case kPOLYGON:
1339  case kMULTIPOLYGON:
1340  constval.stringval = nullptr;
1341  break;
1342  case kFLOAT:
1344  break;
1345  case kDOUBLE:
1347  break;
1348  case kNULLT:
1349  constval.bigintval = 0;
1350  break;
1351  case kARRAY:
1352  constval.arrayval = nullptr;
1353  break;
1354  default:
1355  CHECK(false);
1356  }
1357 }
int8_t tinyintval
Definition: sqltypes.h:232
#define NULL_DOUBLE
Definition: sqltypes.h:63
#define NULL_FLOAT
#define NULL_BIGINT
int8_t boolval
Definition: sqltypes.h:231
VarlenDatum * arrayval
Definition: sqltypes.h:238
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
SQLTypeInfo type_info
Definition: Analyzer.h:183
int32_t intval
Definition: sqltypes.h:234
#define NULL_INT
float floatval
Definition: sqltypes.h:236
int64_t bigintval
Definition: sqltypes.h:235
int16_t smallintval
Definition: sqltypes.h:233
#define NULL_BOOLEAN
std::string * stringval
Definition: sqltypes.h:240
Definition: sqltypes.h:66
Definition: sqltypes.h:67
Definition: sqltypes.h:55
#define NULL_TINYINT
#define CHECK(condition)
Definition: Logger.h:222
#define NULL_SMALLINT
Definition: sqltypes.h:59
double doubleval
Definition: sqltypes.h:237

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

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

2607  {
2608  std::string str{"(Const "};
2609  if (is_null) {
2610  str += "NULL";
2611  } else if (type_info.is_array()) {
2612  const auto& elem_ti = type_info.get_elem_type();
2613  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2614  } else {
2615  str += DatumToString(constval, type_info);
2616  }
2617  str += ") ";
2618  return str;
2619 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:398
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
SQLTypeInfo type_info
Definition: Analyzer.h:183
std::string toString() const override
Definition: Analyzer.cpp:2607
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:981
bool is_array() const
Definition: sqltypes.h:608

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