OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 306 of file Analyzer.h.

Constructor & Destructor Documentation

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

Definition at line 308 of file Analyzer.h.

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

308  : Expr(t, !n), is_null(n) {
309  if (n) {
310  set_null_value();
311  } else {
312  type_info.set_notnull(true);
313  }
314  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
SQLTypeInfo type_info
Definition: Analyzer.h:176
void set_notnull(bool n)
Definition: sqltypes.h:411
char * t

+ Here is the call graph for this function:

Analyzer::Constant::Constant ( SQLTypes  t,
bool  n,
Datum  v 
)
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), constval(v) {
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:69
SQLTypeInfo type_info
Definition: Analyzer.h:176
void set_notnull(bool n)
Definition: sqltypes.h:411
char * t

+ Here is the call graph for this function:

Analyzer::Constant::Constant ( const SQLTypeInfo ti,
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(ti), 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:69
SQLTypeInfo type_info
Definition: Analyzer.h:176
void set_notnull(bool n)
Definition: sqltypes.h:411

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

332  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:348
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:176
std::string * stringval
Definition: sqltypes.h:214
bool is_geometry() const
Definition: sqltypes.h:501
bool is_string() const
Definition: sqltypes.h:489

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

1314  {
1315  if (is_null) {
1316  type_info = new_type_info;
1317  set_null_value();
1318  return shared_from_this();
1319  }
1320  if (new_type_info.get_compression() != type_info.get_compression()) {
1321  if (new_type_info.get_compression() != kENCODING_NONE) {
1322  SQLTypeInfo new_ti = new_type_info;
1323  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1325  }
1326  do_cast(new_ti);
1327  }
1328  return Expr::add_cast(new_type_info);
1329  }
1330  const auto is_integral_type =
1331  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1332  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1333  // Let the codegen phase deal with casts from date/time to a number.
1334  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1335  }
1336  do_cast(new_type_info);
1337  return shared_from_this();
1338 }
void set_compression(EncodingType c)
Definition: sqltypes.h:414
bool is_fp() const
Definition: sqltypes.h:493
Definition: sqldefs.h:49
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool is_time() const
Definition: sqltypes.h:495
bool is_integer() const
Definition: sqltypes.h:491
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1184
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:690
bool contains_agg
Definition: Analyzer.h:177
bool is_decimal() const
Definition: sqltypes.h:492
bool is_date() const
Definition: sqltypes.h:731

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
protected

Definition at line 1115 of file Analyzer.cpp.

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

Referenced by do_cast().

1115  {
1116  std::string* s = constval.stringval;
1117  SQLTypeInfo ti = new_type_info;
1118  constval = StringToDatum(*s, ti);
1119  delete s;
1120  type_info = new_type_info;
1121 }
SQLTypeInfo type_info
Definition: Analyzer.h:176
Datum StringToDatum(std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:239
std::string * stringval
Definition: sqltypes.h:214

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

829  {
830  switch (type_info.get_type()) {
831  case kTINYINT:
832  switch (new_type_info.get_type()) {
833  case kTINYINT:
834  break;
835  case kINT:
836  constval.intval = (int32_t)constval.tinyintval;
837  break;
838  case kSMALLINT:
840  break;
841  case kBIGINT:
842  case kTIMESTAMP:
844  break;
845  case kDOUBLE:
847  break;
848  case kFLOAT:
850  break;
851  case kNUMERIC:
852  case kDECIMAL:
854  break;
855  default:
856  CHECK(false);
857  }
858  break;
859  case kINT:
860  switch (new_type_info.get_type()) {
861  case kTINYINT:
862  constval.tinyintval = safeNarrow<int8_t>(constval.intval);
863  break;
864  case kINT:
865  break;
866  case kSMALLINT:
867  constval.smallintval = safeNarrow<int16_t>(constval.intval);
868  break;
869  case kBIGINT:
870  case kTIMESTAMP:
871  constval.bigintval = (int64_t)constval.intval;
872  break;
873  case kDOUBLE:
874  constval.doubleval = (double)constval.intval;
875  break;
876  case kFLOAT:
877  constval.floatval = (float)constval.intval;
878  break;
879  case kNUMERIC:
880  case kDECIMAL:
881  constval.bigintval = safeScale(constval.intval, new_type_info.get_scale());
882  break;
883  default:
884  CHECK(false);
885  }
886  break;
887  case kSMALLINT:
888  switch (new_type_info.get_type()) {
889  case kTINYINT:
890  constval.tinyintval = safeNarrow<int8_t>(constval.smallintval);
891  break;
892  case kINT:
893  constval.intval = (int32_t)constval.smallintval;
894  break;
895  case kSMALLINT:
896  break;
897  case kBIGINT:
898  case kTIMESTAMP:
900  break;
901  case kDOUBLE:
903  break;
904  case kFLOAT:
906  break;
907  case kNUMERIC:
908  case kDECIMAL:
910  break;
911  default:
912  CHECK(false);
913  }
914  break;
915  case kBIGINT:
916  switch (new_type_info.get_type()) {
917  case kTINYINT:
918  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
919  break;
920  case kINT:
921  constval.intval = safeNarrow<int32_t>(constval.bigintval);
922  break;
923  case kSMALLINT:
924  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
925  break;
926  case kBIGINT:
927  case kTIMESTAMP:
928  break;
929  case kDOUBLE:
931  break;
932  case kFLOAT:
934  break;
935  case kNUMERIC:
936  case kDECIMAL:
938  break;
939  default:
940  CHECK(false);
941  }
942  break;
943  case kDOUBLE:
944  switch (new_type_info.get_type()) {
945  case kTINYINT:
946  constval.tinyintval = safeRound<int8_t>(constval.doubleval);
947  break;
948  case kINT:
949  constval.intval = safeRound<int32_t>(constval.doubleval);
950  break;
951  case kSMALLINT:
952  constval.smallintval = safeRound<int16_t>(constval.doubleval);
953  break;
954  case kBIGINT:
955  case kTIMESTAMP:
956  constval.bigintval = safeRound<int64_t>(constval.doubleval);
957  break;
958  case kDOUBLE:
959  break;
960  case kFLOAT:
962  break;
963  case kNUMERIC:
964  case kDECIMAL:
966  break;
967  default:
968  CHECK(false);
969  }
970  break;
971  case kFLOAT:
972  switch (new_type_info.get_type()) {
973  case kTINYINT:
974  constval.tinyintval = safeRound<int8_t>(constval.floatval);
975  break;
976  case kINT:
977  constval.intval = safeRound<int32_t>(constval.floatval);
978  break;
979  case kSMALLINT:
980  constval.smallintval = safeRound<int16_t>(constval.floatval);
981  break;
982  case kBIGINT:
983  case kTIMESTAMP:
984  constval.bigintval = safeRound<int64_t>(constval.floatval);
985  break;
986  case kDOUBLE:
988  break;
989  case kFLOAT:
990  break;
991  case kNUMERIC:
992  case kDECIMAL:
994  break;
995  default:
996  CHECK(false);
997  }
998  break;
999  case kNUMERIC:
1000  case kDECIMAL:
1001  switch (new_type_info.get_type()) {
1002  case kTINYINT:
1004  roundDecimal<int8_t>(constval.bigintval, type_info.get_scale());
1005  break;
1006  case kINT:
1007  constval.intval =
1008  roundDecimal<int32_t>(constval.bigintval, type_info.get_scale());
1009  break;
1010  case kSMALLINT:
1012  roundDecimal<int16_t>(constval.bigintval, type_info.get_scale());
1013  break;
1014  case kBIGINT:
1015  case kTIMESTAMP:
1017  roundDecimal<int64_t>(constval.bigintval, type_info.get_scale());
1018  break;
1019  case kDOUBLE:
1021  floatFromDecimal<double>(constval.bigintval, type_info.get_scale());
1022  break;
1023  case kFLOAT:
1024  constval.floatval =
1025  floatFromDecimal<float>(constval.bigintval, type_info.get_scale());
1026  break;
1027  case kNUMERIC:
1028  case kDECIMAL:
1030  constval.bigintval, type_info, new_type_info);
1031  break;
1032  default:
1033  CHECK(false);
1034  }
1035  break;
1036  case kTIMESTAMP:
1037  switch (new_type_info.get_type()) {
1038  case kTINYINT:
1039  constval.tinyintval = safeNarrow<int8_t>(constval.bigintval);
1040  break;
1041  case kINT:
1042  constval.intval = safeNarrow<int32_t>(constval.bigintval);
1043  break;
1044  case kSMALLINT:
1045  constval.smallintval = safeNarrow<int16_t>(constval.bigintval);
1046  break;
1047  case kBIGINT:
1048  case kTIMESTAMP:
1049  break;
1050  case kDOUBLE:
1051  constval.doubleval = static_cast<double>(constval.bigintval);
1052  break;
1053  case kFLOAT:
1054  constval.floatval = static_cast<float>(constval.bigintval);
1055  break;
1056  case kNUMERIC:
1057  case kDECIMAL:
1058  for (int i = 0; i < new_type_info.get_scale(); i++) {
1059  constval.bigintval *= 10;
1060  }
1061  break;
1062  default:
1063  CHECK(false);
1064  }
1065  break;
1066  case kBOOLEAN:
1067  switch (new_type_info.get_type()) {
1068  case kTINYINT:
1069  constval.tinyintval = constval.boolval ? 1 : 0;
1070  break;
1071  case kINT:
1072  constval.intval = constval.boolval ? 1 : 0;
1073  break;
1074  case kSMALLINT:
1076  break;
1077  case kBIGINT:
1078  case kTIMESTAMP:
1079  constval.bigintval = constval.boolval ? 1 : 0;
1080  break;
1081  case kDOUBLE:
1082  constval.doubleval = constval.boolval ? 1 : 0;
1083  break;
1084  case kFLOAT:
1085  constval.floatval = constval.boolval ? 1 : 0;
1086  break;
1087  case kNUMERIC:
1088  case kDECIMAL:
1089  constval.bigintval = constval.boolval ? 1 : 0;
1090  for (int i = 0; i < new_type_info.get_scale(); i++) {
1091  constval.bigintval *= 10;
1092  }
1093  break;
1094  default:
1095  CHECK(false);
1096  }
1097  break;
1098  default:
1099  CHECK(false);
1100  }
1101  type_info = new_type_info;
1102 }
int8_t tinyintval
Definition: sqltypes.h:206
bool boolval
Definition: sqltypes.h:205
HOST DEVICE int get_scale() const
Definition: sqltypes.h:319
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
SQLTypeInfo type_info
Definition: Analyzer.h:176
int32_t intval
Definition: sqltypes.h:208
float floatval
Definition: sqltypes.h:210
int64_t bigintval
Definition: sqltypes.h:209
int16_t smallintval
Definition: sqltypes.h:207
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:437
int64_t safeScale(T from, unsigned const scale)
Definition: Analyzer.cpp:807
#define CHECK(condition)
Definition: Logger.h:203
Definition: sqltypes.h:44
double doubleval
Definition: sqltypes.h:211

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

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

Referenced by do_cast().

1104  {
1105  std::string* s = constval.stringval;
1106  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1107  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1108  // truncate string
1109  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1110  delete s;
1111  }
1112  type_info = new_type_info;
1113 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::string * stringval
Definition: sqltypes.h:214
Definition: sqltypes.h:51
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:316

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

1123  {
1124  const auto str_val = DatumToString(constval, type_info);
1125  constval.stringval = new std::string(str_val);
1126  if (str_type_info.get_type() != kTEXT &&
1127  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1128  // truncate the string
1129  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1130  }
1131  type_info = str_type_info;
1132 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:356
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::string * stringval
Definition: sqltypes.h:214
Definition: sqltypes.h:51

+ 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, test_fsi::d, 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 }
tuple d
Definition: test_fsi.py:9
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
SQLTypeInfo type_info
Definition: Analyzer.h:176
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:348
std::string * stringval
Definition: sqltypes.h:214
bool is_geometry() const
Definition: sqltypes.h:501
bool is_string() const
Definition: sqltypes.h:489

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

1184  {
1185  if (type_info == new_type_info) {
1186  return;
1187  }
1188  if (is_null && !new_type_info.get_notnull()) {
1189  type_info = new_type_info;
1190  set_null_value();
1191  return;
1192  }
1193  if ((new_type_info.is_number() || new_type_info.get_type() == kTIMESTAMP) &&
1194  (new_type_info.get_type() != kTIMESTAMP || type_info.get_type() != kTIMESTAMP) &&
1196  type_info.get_type() == kBOOLEAN)) {
1197  cast_number(new_type_info);
1198  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1199  type_info = new_type_info;
1200  } else if (new_type_info.is_geometry() &&
1201  type_info.get_type() == new_type_info.get_type()) {
1202  type_info = new_type_info;
1203  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1204  type_info = new_type_info;
1205  } else if (new_type_info.is_string() && type_info.is_string()) {
1206  cast_string(new_type_info);
1207  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1208  cast_from_string(new_type_info);
1209  } else if (new_type_info.is_string()) {
1210  cast_to_string(new_type_info);
1211  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1212  type_info = new_type_info;
1213  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1219  : DateTruncate(dtDAY, constval.bigintval);
1220  type_info = new_type_info;
1221  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1222  new_type_info.get_type() == kTIMESTAMP) {
1223  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1224  if (dimen != new_type_info.get_dimension()) {
1225  constval.bigintval = dimen < new_type_info.get_dimension()
1229  new_type_info.get_dimension() - dimen)
1233  dimen - new_type_info.get_dimension());
1234  }
1235  type_info = new_type_info;
1236  } else if (new_type_info.is_array() && type_info.is_array()) {
1237  auto new_sub_ti = new_type_info.get_elem_type();
1238  for (auto& v : value_list) {
1239  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1240  if (!c) {
1241  throw std::runtime_error("Invalid array cast.");
1242  }
1243  c->do_cast(new_sub_ti);
1244  }
1245  type_info = new_type_info;
1246  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1247  new_type_info.is_string() || new_type_info.is_boolean())) {
1248  type_info = new_type_info;
1249  set_null_value();
1250  } else if (!is_null_value(type_info, constval) &&
1251  get_nullable_type_info(type_info) == new_type_info) {
1252  CHECK(!is_null);
1253  // relax nullability
1254  type_info = new_type_info;
1255  return;
1256  } else {
1257  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1258  new_type_info.get_type_name() + " not supported");
1259  }
1260 }
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1140
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool get_is_null() const
Definition: Analyzer.h:334
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1115
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
bool is_number() const
Definition: sqltypes.h:494
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool is_time() const
Definition: sqltypes.h:495
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1104
int64_t bigintval
Definition: sqltypes.h:209
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:348
bool is_boolean() const
Definition: sqltypes.h:496
Definition: sqltypes.h:52
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:316
std::string get_type_name() const
Definition: sqltypes.h:417
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:829
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
#define CHECK(condition)
Definition: Logger.h:203
bool is_geometry() const
Definition: sqltypes.h:501
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:733
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1123
bool is_string() const
Definition: sqltypes.h:489
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:713
bool is_array() const
Definition: sqltypes.h:497
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:926

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

References value_list.

Referenced by CgenState::getOrAddLiteral().

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

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

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

2156  {
2157  if (typeid(rhs) != typeid(Constant)) {
2158  return false;
2159  }
2160  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2161  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2162  return false;
2163  }
2164  if (is_null && rhs_c.get_is_null()) {
2165  return true;
2166  }
2167  if (type_info.is_array()) {
2168  return false;
2169  }
2170  return Datum_equal(type_info, constval, rhs_c.get_constval());
2171 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2115
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool is_array() const
Definition: sqltypes.h:497

+ Here is the call graph for this function:

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

Definition at line 336 of file Analyzer.h.

References constval, and test_fsi::d.

336 { constval = d; }
tuple d
Definition: test_fsi.py:9
void Constant::set_null_value ( )
protected

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

1262  {
1263  switch (type_info.get_type()) {
1264  case kBOOLEAN:
1266  break;
1267  case kTINYINT:
1269  break;
1270  case kINT:
1272  break;
1273  case kSMALLINT:
1275  break;
1276  case kBIGINT:
1277  case kNUMERIC:
1278  case kDECIMAL:
1280  break;
1281  case kTIME:
1282  case kTIMESTAMP:
1283  case kDATE:
1285  break;
1286  case kVARCHAR:
1287  case kCHAR:
1288  case kTEXT:
1289  constval.stringval = nullptr;
1290  break;
1291  case kPOINT:
1292  case kLINESTRING:
1293  case kPOLYGON:
1294  case kMULTIPOLYGON:
1295  constval.stringval = nullptr;
1296  break;
1297  case kFLOAT:
1299  break;
1300  case kDOUBLE:
1302  break;
1303  case kNULLT:
1304  constval.bigintval = 0;
1305  break;
1306  case kARRAY:
1307  constval.arrayval = nullptr;
1308  break;
1309  default:
1310  CHECK(false);
1311  }
1312 }
int8_t tinyintval
Definition: sqltypes.h:206
#define NULL_DOUBLE
Definition: sqltypes.h:48
#define NULL_FLOAT
#define NULL_BIGINT
bool boolval
Definition: sqltypes.h:205
VarlenDatum * arrayval
Definition: sqltypes.h:212
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
SQLTypeInfo type_info
Definition: Analyzer.h:176
int32_t intval
Definition: sqltypes.h:208
#define NULL_INT
float floatval
Definition: sqltypes.h:210
int64_t bigintval
Definition: sqltypes.h:209
int16_t smallintval
Definition: sqltypes.h:207
#define NULL_BOOLEAN
std::string * stringval
Definition: sqltypes.h:214
Definition: sqltypes.h:51
Definition: sqltypes.h:52
Definition: sqltypes.h:40
#define NULL_TINYINT
#define CHECK(condition)
Definition: Logger.h:203
#define NULL_SMALLINT
Definition: sqltypes.h:44
double doubleval
Definition: sqltypes.h:211

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

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

2478  {
2479  std::string str{"(Const "};
2480  if (is_null) {
2481  str += "NULL";
2482  } else if (type_info.is_array()) {
2483  const auto& elem_ti = type_info.get_elem_type();
2484  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2485  } else {
2486  str += DatumToString(constval, type_info);
2487  }
2488  str += ") ";
2489  return str;
2490 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:356
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::string toString() const override
Definition: Analyzer.cpp:2478
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:713
bool is_array() const
Definition: sqltypes.h:497

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