OmniSciDB  06b3bd477c
 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
 

Private 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 ()
 

Private Attributes

bool is_null
 
Datum constval
 
const std::list
< std::shared_ptr
< Analyzer::Expr > > 
value_list
 

Additional Inherited Members

- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 307 of file Analyzer.h.

Constructor & Destructor Documentation

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

Definition at line 309 of file Analyzer.h.

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

309  : Expr(t, !n), is_null(n) {
310  if (n) {
311  set_null_value();
312  } else {
313  type_info.set_notnull(true);
314  }
315  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
SQLTypeInfo type_info
Definition: Analyzer.h:177
void set_notnull(bool n)
Definition: sqltypes.h:355

+ Here is the call graph for this function:

Analyzer::Constant::Constant ( SQLTypes  t,
bool  n,
Datum  v 
)
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), constval(v) {
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:70
SQLTypeInfo type_info
Definition: Analyzer.h:177
void set_notnull(bool n)
Definition: sqltypes.h:355

+ Here is the call graph for this function:

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

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

333  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:349
Constant::~Constant ( )
override

Definition at line 41 of file Analyzer.cpp.

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

41  {
42  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
43  delete constval.stringval;
44  }
45 }
SQLTypeInfo type_info
Definition: Analyzer.h:177
std::string * stringval
Definition: sqltypes.h:142
bool is_geometry() const
Definition: sqltypes.h:427
bool is_string() const
Definition: sqltypes.h:415

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

1261  {
1262  if (is_null) {
1263  type_info = new_type_info;
1264  set_null_value();
1265  return shared_from_this();
1266  }
1267  if (new_type_info.get_compression() != type_info.get_compression()) {
1268  if (new_type_info.get_compression() != kENCODING_NONE) {
1269  SQLTypeInfo new_ti = new_type_info;
1270  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1272  }
1273  do_cast(new_ti);
1274  }
1275  return Expr::add_cast(new_type_info);
1276  }
1277  const auto is_integral_type =
1278  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1279  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1280  // Let the codegen phase deal with casts from date/time to a number.
1281  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1282  }
1283  do_cast(new_type_info);
1284  return shared_from_this();
1285 }
void set_compression(EncodingType c)
Definition: sqltypes.h:358
bool is_fp() const
Definition: sqltypes.h:419
Definition: sqldefs.h:49
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool is_time() const
Definition: sqltypes.h:421
bool is_integer() const
Definition: sqltypes.h:417
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1132
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:689
bool contains_agg
Definition: Analyzer.h:178
bool is_decimal() const
Definition: sqltypes.h:418
bool is_date() const
Definition: sqltypes.h:640

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
private

Definition at line 1063 of file Analyzer.cpp.

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

Referenced by do_cast().

1063  {
1064  std::string* s = constval.stringval;
1065  SQLTypeInfo ti = new_type_info;
1066  constval = StringToDatum(*s, ti);
1067  delete s;
1068  type_info = new_type_info;
1069 }
SQLTypeInfo type_info
Definition: Analyzer.h:177
Datum StringToDatum(std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:124
std::string * stringval
Definition: sqltypes.h:142

+ 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)
private

Definition at line 757 of file Analyzer.cpp.

References Datum::bigintval, Datum::boolval, CHECK(), constval, convert_decimal_value_to_scale(), Analyzer::anonymous_namespace{Analyzer.cpp}::decimal_to_int_frac(), Datum::doubleval, Datum::floatval, SQLTypeInfo::get_scale(), SQLTypeInfo::get_type(), Datum::intval, kBIGINT, kBOOLEAN, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTIMESTAMP, kTINYINT, Datum::smallintval, Datum::tinyintval, and Analyzer::Expr::type_info.

Referenced by do_cast().

757  {
758  switch (type_info.get_type()) {
759  case kTINYINT:
760  switch (new_type_info.get_type()) {
761  case kTINYINT:
762  break;
763  case kINT:
764  constval.intval = (int32_t)constval.tinyintval;
765  break;
766  case kSMALLINT:
768  break;
769  case kBIGINT:
771  break;
772  case kDOUBLE:
774  break;
775  case kFLOAT:
777  break;
778  case kNUMERIC:
779  case kDECIMAL:
781  for (int i = 0; i < new_type_info.get_scale(); i++) {
782  constval.bigintval *= 10;
783  }
784  break;
785  default:
786  CHECK(false);
787  }
788  break;
789  case kINT:
790  switch (new_type_info.get_type()) {
791  case kTINYINT:
792  constval.tinyintval = safe_narrow<int8_t>(constval.intval);
793  break;
794  case kINT:
795  break;
796  case kSMALLINT:
797  constval.smallintval = safe_narrow<int16_t>(constval.intval);
798  break;
799  case kBIGINT:
800  constval.bigintval = (int64_t)constval.intval;
801  break;
802  case kDOUBLE:
803  constval.doubleval = (double)constval.intval;
804  break;
805  case kFLOAT:
806  constval.floatval = (float)constval.intval;
807  break;
808  case kNUMERIC:
809  case kDECIMAL:
810  constval.bigintval = (int64_t)constval.intval;
811  for (int i = 0; i < new_type_info.get_scale(); i++) {
812  constval.bigintval *= 10;
813  }
814  break;
815  default:
816  CHECK(false);
817  }
818  break;
819  case kSMALLINT:
820  switch (new_type_info.get_type()) {
821  case kTINYINT:
822  constval.tinyintval = safe_narrow<int8_t>(constval.smallintval);
823  break;
824  case kINT:
825  constval.intval = (int32_t)constval.smallintval;
826  break;
827  case kSMALLINT:
828  break;
829  case kBIGINT:
831  break;
832  case kDOUBLE:
834  break;
835  case kFLOAT:
837  break;
838  case kNUMERIC:
839  case kDECIMAL:
841  for (int i = 0; i < new_type_info.get_scale(); i++) {
842  constval.bigintval *= 10;
843  }
844  break;
845  default:
846  CHECK(false);
847  }
848  break;
849  case kBIGINT:
850  switch (new_type_info.get_type()) {
851  case kTINYINT:
852  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
853  break;
854  case kINT:
855  constval.intval = safe_narrow<int32_t>(constval.bigintval);
856  break;
857  case kSMALLINT:
858  constval.smallintval = safe_narrow<int16_t>(constval.bigintval);
859  break;
860  case kBIGINT:
861  break;
862  case kDOUBLE:
864  break;
865  case kFLOAT:
867  break;
868  case kNUMERIC:
869  case kDECIMAL:
870  for (int i = 0; i < new_type_info.get_scale(); i++) {
871  constval.bigintval *= 10;
872  }
873  break;
874  default:
875  CHECK(false);
876  }
877  break;
878  case kDOUBLE:
879  switch (new_type_info.get_type()) {
880  case kTINYINT:
882  break;
883  case kINT:
884  constval.intval = (int32_t)constval.doubleval;
885  break;
886  case kSMALLINT:
888  break;
889  case kBIGINT:
891  break;
892  case kDOUBLE:
893  break;
894  case kFLOAT:
896  break;
897  case kNUMERIC:
898  case kDECIMAL:
899  for (int i = 0; i < new_type_info.get_scale(); i++) {
900  constval.doubleval *= 10;
901  }
903  break;
904  default:
905  CHECK(false);
906  }
907  break;
908  case kFLOAT:
909  switch (new_type_info.get_type()) {
910  case kTINYINT:
912  break;
913  case kINT:
914  constval.intval = (int32_t)constval.floatval;
915  break;
916  case kSMALLINT:
918  break;
919  case kBIGINT:
920  constval.bigintval = (int64_t)constval.floatval;
921  break;
922  case kDOUBLE:
924  break;
925  case kFLOAT:
926  break;
927  case kNUMERIC:
928  case kDECIMAL:
929  for (int i = 0; i < new_type_info.get_scale(); i++) {
930  constval.floatval *= 10;
931  }
932  constval.bigintval = (int64_t)constval.floatval;
933  break;
934  default:
935  CHECK(false);
936  }
937  break;
938  case kNUMERIC:
939  case kDECIMAL:
940  switch (new_type_info.get_type()) {
941  case kTINYINT:
942  for (int i = 0; i < type_info.get_scale(); i++) {
943  constval.bigintval /= 10;
944  }
945  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
946  break;
947  case kINT:
948  for (int i = 0; i < type_info.get_scale(); i++) {
949  constval.bigintval /= 10;
950  }
951  constval.intval = safe_narrow<int32_t>(constval.bigintval);
952  break;
953  case kSMALLINT:
954  for (int i = 0; i < type_info.get_scale(); i++) {
955  constval.bigintval /= 10;
956  }
958  break;
959  case kBIGINT:
960  for (int i = 0; i < type_info.get_scale(); i++) {
961  constval.bigintval /= 10;
962  }
963  break;
964  case kDOUBLE: {
965  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
966  constval.doubleval = int_frac.integral +
967  static_cast<double>(int_frac.fractional) / int_frac.scale;
968  break;
969  }
970  case kFLOAT: {
971  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
972  constval.floatval = int_frac.integral +
973  static_cast<double>(int_frac.fractional) / int_frac.scale;
974  break;
975  }
976  case kNUMERIC:
977  case kDECIMAL:
979  constval.bigintval, type_info, new_type_info);
980  break;
981  default:
982  CHECK(false);
983  }
984  break;
985  case kTIMESTAMP:
986  switch (new_type_info.get_type()) {
987  case kTINYINT:
988  constval.tinyintval = static_cast<int8_t>(constval.bigintval);
989  break;
990  case kINT:
991  constval.intval = static_cast<int32_t>(constval.bigintval);
992  break;
993  case kSMALLINT:
994  constval.smallintval = static_cast<int16_t>(constval.bigintval);
995  break;
996  case kBIGINT:
997  constval.bigintval = static_cast<int64_t>(constval.bigintval);
998  break;
999  case kDOUBLE:
1000  constval.doubleval = static_cast<double>(constval.bigintval);
1001  break;
1002  case kFLOAT:
1003  constval.floatval = static_cast<float>(constval.bigintval);
1004  break;
1005  case kNUMERIC:
1006  case kDECIMAL:
1007  for (int i = 0; i < new_type_info.get_scale(); i++) {
1008  constval.bigintval *= 10;
1009  }
1010  break;
1011  default:
1012  CHECK(false);
1013  }
1014  break;
1015  case kBOOLEAN:
1016  switch (new_type_info.get_type()) {
1017  case kTINYINT:
1018  constval.tinyintval = constval.boolval ? 1 : 0;
1019  break;
1020  case kINT:
1021  constval.intval = constval.boolval ? 1 : 0;
1022  break;
1023  case kSMALLINT:
1025  break;
1026  case kBIGINT:
1027  constval.bigintval = constval.boolval ? 1 : 0;
1028  break;
1029  case kDOUBLE:
1030  constval.doubleval = constval.boolval ? 1 : 0;
1031  break;
1032  case kFLOAT:
1033  constval.floatval = constval.boolval ? 1 : 0;
1034  break;
1035  case kNUMERIC:
1036  case kDECIMAL:
1037  constval.bigintval = constval.boolval ? 1 : 0;
1038  for (int i = 0; i < new_type_info.get_scale(); i++) {
1039  constval.bigintval *= 10;
1040  }
1041  break;
1042  default:
1043  CHECK(false);
1044  }
1045  break;
1046  default:
1047  CHECK(false);
1048  }
1049  type_info = new_type_info;
1050 }
int8_t tinyintval
Definition: sqltypes.h:134
bool boolval
Definition: sqltypes.h:133
HOST DEVICE int get_scale() const
Definition: sqltypes.h:263
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
SQLTypeInfo type_info
Definition: Analyzer.h:177
int32_t intval
Definition: sqltypes.h:136
float floatval
Definition: sqltypes.h:138
CHECK(cgen_state)
int64_t bigintval
Definition: sqltypes.h:137
int16_t smallintval
Definition: sqltypes.h:135
IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:728
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:327
Definition: sqltypes.h:46
double doubleval
Definition: sqltypes.h:139

+ 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)
private

Definition at line 1052 of file Analyzer.cpp.

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

Referenced by do_cast().

1052  {
1053  std::string* s = constval.stringval;
1054  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1055  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1056  // truncate string
1057  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1058  delete s;
1059  }
1060  type_info = new_type_info;
1061 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
SQLTypeInfo type_info
Definition: Analyzer.h:177
std::string * stringval
Definition: sqltypes.h:142
Definition: sqltypes.h:53
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:260

+ 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)
private

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

1071  {
1072  const auto str_val = DatumToString(constval, type_info);
1073  constval.stringval = new std::string(str_val);
1074  if (str_type_info.get_type() != kTEXT &&
1075  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1076  // truncate the string
1077  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1078  }
1079  type_info = str_type_info;
1080 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:230
SQLTypeInfo type_info
Definition: Analyzer.h:177
std::string * stringval
Definition: sqltypes.h:142
Definition: sqltypes.h:53

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

84  {
85  Datum d = constval;
86  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
87  d.stringval = new std::string(*constval.stringval);
88  }
89  if (type_info.get_type() == kARRAY) {
90  return makeExpr<Constant>(type_info, is_null, value_list);
91  }
92  return makeExpr<Constant>(type_info, is_null, d);
93 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
SQLTypeInfo type_info
Definition: Analyzer.h:177
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:349
std::string * stringval
Definition: sqltypes.h:142
bool is_geometry() const
Definition: sqltypes.h:427
bool is_string() const
Definition: sqltypes.h:415

+ 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)
private

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

1132  {
1133  if (type_info == new_type_info) {
1134  return;
1135  }
1136  if (is_null && !new_type_info.get_notnull()) {
1137  type_info = new_type_info;
1138  set_null_value();
1139  return;
1140  }
1141  if (new_type_info.is_number() &&
1143  type_info.get_type() == kBOOLEAN)) {
1144  cast_number(new_type_info);
1145  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1146  type_info = new_type_info;
1147  } else if (new_type_info.is_geometry() &&
1148  type_info.get_type() == new_type_info.get_type()) {
1149  type_info = new_type_info;
1150  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1151  type_info = new_type_info;
1152  } else if (new_type_info.is_string() && type_info.is_string()) {
1153  cast_string(new_type_info);
1154  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1155  cast_from_string(new_type_info);
1156  } else if (new_type_info.is_string()) {
1157  cast_to_string(new_type_info);
1158  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1159  type_info = new_type_info;
1160  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1166  : DateTruncate(dtDAY, constval.bigintval);
1167  type_info = new_type_info;
1168  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1169  new_type_info.get_type() == kTIMESTAMP) {
1170  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1171  if (dimen != new_type_info.get_dimension()) {
1172  constval.bigintval = dimen < new_type_info.get_dimension()
1176  new_type_info.get_dimension() - dimen)
1180  dimen - new_type_info.get_dimension());
1181  }
1182  type_info = new_type_info;
1183  } else if (new_type_info.is_array() && type_info.is_array()) {
1184  auto new_sub_ti = new_type_info.get_elem_type();
1185  for (auto& v : value_list) {
1186  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1187  if (!c) {
1188  throw std::runtime_error("Invalid array cast.");
1189  }
1190  c->do_cast(new_sub_ti);
1191  }
1192  type_info = new_type_info;
1193  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1194  new_type_info.is_string() || new_type_info.is_boolean())) {
1195  type_info = new_type_info;
1196  set_null_value();
1197  } else if (!is_null_value(type_info, constval) &&
1198  get_nullable_type_info(type_info) == new_type_info) {
1199  CHECK(!is_null);
1200  // relax nullability
1201  type_info = new_type_info;
1202  return;
1203  } else {
1204  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1205  new_type_info.get_type_name() + " not supported");
1206  }
1207 }
NEVER_INLINE DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1088
bool get_is_null() const
Definition: Analyzer.h:335
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1063
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
bool is_number() const
Definition: sqltypes.h:420
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool is_time() const
Definition: sqltypes.h:421
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1052
CHECK(cgen_state)
int64_t bigintval
Definition: sqltypes.h:137
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:349
bool is_boolean() const
Definition: sqltypes.h:422
Definition: sqltypes.h:54
DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:260
std::string get_type_name() const
Definition: sqltypes.h:361
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:757
bool is_geometry() const
Definition: sqltypes.h:427
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:642
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1071
bool is_string() const
Definition: sqltypes.h:415
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:265
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:622
bool is_array() const
Definition: sqltypes.h:423
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:833

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

References value_list.

Referenced by CgenState::getOrAddLiteral().

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

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

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

2103  {
2104  if (typeid(rhs) != typeid(Constant)) {
2105  return false;
2106  }
2107  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2108  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2109  return false;
2110  }
2111  if (is_null && rhs_c.get_is_null()) {
2112  return true;
2113  }
2114  if (type_info.is_array()) {
2115  return false;
2116  }
2117  return Datum_equal(type_info, constval, rhs_c.get_constval());
2118 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:2062
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool is_array() const
Definition: sqltypes.h:423

+ Here is the call graph for this function:

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

Definition at line 337 of file Analyzer.h.

References constval.

337 { constval = d; }
void Constant::set_null_value ( )
private

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

1209  {
1210  switch (type_info.get_type()) {
1211  case kBOOLEAN:
1213  break;
1214  case kTINYINT:
1216  break;
1217  case kINT:
1219  break;
1220  case kSMALLINT:
1222  break;
1223  case kBIGINT:
1224  case kNUMERIC:
1225  case kDECIMAL:
1227  break;
1228  case kTIME:
1229  case kTIMESTAMP:
1230  case kDATE:
1232  break;
1233  case kVARCHAR:
1234  case kCHAR:
1235  case kTEXT:
1236  constval.stringval = nullptr;
1237  break;
1238  case kPOINT:
1239  case kLINESTRING:
1240  case kPOLYGON:
1241  case kMULTIPOLYGON:
1242  constval.stringval = nullptr;
1243  break;
1244  case kFLOAT:
1246  break;
1247  case kDOUBLE:
1249  break;
1250  case kNULLT:
1251  constval.bigintval = 0;
1252  break;
1253  case kARRAY:
1254  constval.arrayval = nullptr;
1255  break;
1256  default:
1257  CHECK(false);
1258  }
1259 }
int8_t tinyintval
Definition: sqltypes.h:134
#define NULL_DOUBLE
Definition: sqltypes.h:185
Definition: sqltypes.h:50
#define NULL_BIGINT
Definition: sqltypes.h:183
bool boolval
Definition: sqltypes.h:133
VarlenDatum * arrayval
Definition: sqltypes.h:140
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
SQLTypeInfo type_info
Definition: Analyzer.h:177
int32_t intval
Definition: sqltypes.h:136
float floatval
Definition: sqltypes.h:138
CHECK(cgen_state)
#define NULL_TINYINT
Definition: sqltypes.h:180
int64_t bigintval
Definition: sqltypes.h:137
#define NULL_FLOAT
Definition: sqltypes.h:184
int16_t smallintval
Definition: sqltypes.h:135
#define NULL_INT
Definition: sqltypes.h:182
std::string * stringval
Definition: sqltypes.h:142
Definition: sqltypes.h:53
Definition: sqltypes.h:54
Definition: sqltypes.h:42
#define NULL_SMALLINT
Definition: sqltypes.h:181
Definition: sqltypes.h:46
#define NULL_BOOLEAN
Definition: sqltypes.h:179
double doubleval
Definition: sqltypes.h:139

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

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

2425  {
2426  std::string str{"(Const "};
2427  if (is_null) {
2428  str += "NULL";
2429  } else if (type_info.is_array()) {
2430  const auto& elem_ti = type_info.get_elem_type();
2431  str += sql_type_to_str(type_info.get_type()) + ": " +
2432  sql_type_to_str(elem_ti.get_type());
2433  } else {
2434  str += DatumToString(constval, type_info);
2435  }
2436  str += ") ";
2437  return str;
2438 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:230
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
SQLTypeInfo type_info
Definition: Analyzer.h:177
std::string sql_type_to_str(const SQLTypes &type)
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:622
bool is_array() const
Definition: sqltypes.h:423

+ Here is the call graph for this function:

Member Data Documentation

bool Analyzer::Constant::is_null
private

Definition at line 347 of file Analyzer.h.

Referenced by add_cast(), deep_copy(), do_cast(), get_is_null(), operator==(), toString(), and ~Constant().

const std::list<std::shared_ptr<Analyzer::Expr> > Analyzer::Constant::value_list
private

Definition at line 349 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: