OmniSciDB  b24e664e58
 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 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 set_null_value().

308  : Expr(t, !n), is_null(n) {
309  if (n) {
310  set_null_value();
311  }
312  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69

+ Here is the call graph for this function:

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

Definition at line 313 of file Analyzer.h.

References set_null_value().

313  : Expr(t, !n), is_null(n), constval(v) {
314  if (n) {
315  set_null_value();
316  }
317  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69

+ Here is the call graph for this function:

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

Definition at line 318 of file Analyzer.h.

References set_null_value().

318  : Expr(ti), is_null(n), constval(v) {
319  if (n) {
320  set_null_value();
321  }
322  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69

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

326  : 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:342
Constant::~Constant ( )
override

Definition at line 41 of file Analyzer.cpp.

References constval, SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), is_null, SQLTypeInfoCore< TYPE_FACET_PACK >::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:176
bool is_geometry() const
Definition: sqltypes.h:489
std::string * stringval
Definition: sqltypes.h:134
bool is_string() const
Definition: sqltypes.h:477

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

References Analyzer::Expr::add_cast(), Analyzer::Expr::contains_agg, do_cast(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), is_null, kCAST, kENCODING_DATE_IN_DAYS, kENCODING_NONE, SQLTypeInfoCore< TYPE_FACET_PACK >::set_compression(), set_null_value(), and Analyzer::Expr::type_info.

1187  {
1188  if (is_null) {
1189  type_info = new_type_info;
1190  set_null_value();
1191  return shared_from_this();
1192  }
1193  if (new_type_info.get_compression() != type_info.get_compression()) {
1194  if (new_type_info.get_compression() != kENCODING_NONE) {
1195  SQLTypeInfo new_ti = new_type_info;
1196  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1198  }
1199  do_cast(new_ti);
1200  }
1201  return Expr::add_cast(new_type_info);
1202  }
1203  if (is_member_of_typeset<kINT, kDECIMAL, kFLOAT, kDOUBLE>(new_type_info) &&
1204  is_member_of_typeset<kTIME, kDATE>(type_info)) {
1205  // Let the codegen phase deal with casts from date/time to a number.
1206  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1207  }
1208  do_cast(new_type_info);
1209  return shared_from_this();
1210 }
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
Definition: sqldefs.h:49
void set_compression(EncodingType c)
Definition: sqltypes.h:426
SQLTypeInfo type_info
Definition: Analyzer.h:176
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1064
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:671
bool contains_agg
Definition: Analyzer.h:177

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
private

Definition at line 1045 of file Analyzer.cpp.

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

Referenced by do_cast().

1045  {
1046  std::string* s = constval.stringval;
1047  SQLTypeInfo ti = new_type_info;
1048  constval = StringToDatum(*s, ti);
1049  delete s;
1050  type_info = new_type_info;
1051 }
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::string * stringval
Definition: sqltypes.h:134
Datum StringToDatum(const std::string &s, SQLTypeInfo &ti)
Definition: Datum.cpp:90

+ 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 739 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, SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::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().

739  {
740  switch (type_info.get_type()) {
741  case kTINYINT:
742  switch (new_type_info.get_type()) {
743  case kTINYINT:
744  break;
745  case kINT:
746  constval.intval = (int32_t)constval.tinyintval;
747  break;
748  case kSMALLINT:
750  break;
751  case kBIGINT:
753  break;
754  case kDOUBLE:
756  break;
757  case kFLOAT:
759  break;
760  case kNUMERIC:
761  case kDECIMAL:
763  for (int i = 0; i < new_type_info.get_scale(); i++) {
764  constval.bigintval *= 10;
765  }
766  break;
767  default:
768  CHECK(false);
769  }
770  break;
771  case kINT:
772  switch (new_type_info.get_type()) {
773  case kTINYINT:
774  constval.tinyintval = safe_narrow<int8_t>(constval.intval);
775  break;
776  case kINT:
777  break;
778  case kSMALLINT:
779  constval.smallintval = safe_narrow<int16_t>(constval.intval);
780  break;
781  case kBIGINT:
782  constval.bigintval = (int64_t)constval.intval;
783  break;
784  case kDOUBLE:
785  constval.doubleval = (double)constval.intval;
786  break;
787  case kFLOAT:
788  constval.floatval = (float)constval.intval;
789  break;
790  case kNUMERIC:
791  case kDECIMAL:
792  constval.bigintval = (int64_t)constval.intval;
793  for (int i = 0; i < new_type_info.get_scale(); i++) {
794  constval.bigintval *= 10;
795  }
796  break;
797  default:
798  CHECK(false);
799  }
800  break;
801  case kSMALLINT:
802  switch (new_type_info.get_type()) {
803  case kTINYINT:
804  constval.tinyintval = safe_narrow<int8_t>(constval.smallintval);
805  break;
806  case kINT:
807  constval.intval = (int32_t)constval.smallintval;
808  break;
809  case kSMALLINT:
810  break;
811  case kBIGINT:
813  break;
814  case kDOUBLE:
816  break;
817  case kFLOAT:
819  break;
820  case kNUMERIC:
821  case kDECIMAL:
823  for (int i = 0; i < new_type_info.get_scale(); i++) {
824  constval.bigintval *= 10;
825  }
826  break;
827  default:
828  CHECK(false);
829  }
830  break;
831  case kBIGINT:
832  switch (new_type_info.get_type()) {
833  case kTINYINT:
834  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
835  break;
836  case kINT:
837  constval.intval = safe_narrow<int32_t>(constval.bigintval);
838  break;
839  case kSMALLINT:
840  constval.smallintval = safe_narrow<int16_t>(constval.bigintval);
841  break;
842  case kBIGINT:
843  break;
844  case kDOUBLE:
846  break;
847  case kFLOAT:
849  break;
850  case kNUMERIC:
851  case kDECIMAL:
852  for (int i = 0; i < new_type_info.get_scale(); i++) {
853  constval.bigintval *= 10;
854  }
855  break;
856  default:
857  CHECK(false);
858  }
859  break;
860  case kDOUBLE:
861  switch (new_type_info.get_type()) {
862  case kTINYINT:
864  break;
865  case kINT:
866  constval.intval = (int32_t)constval.doubleval;
867  break;
868  case kSMALLINT:
870  break;
871  case kBIGINT:
873  break;
874  case kDOUBLE:
875  break;
876  case kFLOAT:
878  break;
879  case kNUMERIC:
880  case kDECIMAL:
881  for (int i = 0; i < new_type_info.get_scale(); i++) {
882  constval.doubleval *= 10;
883  }
885  break;
886  default:
887  CHECK(false);
888  }
889  break;
890  case kFLOAT:
891  switch (new_type_info.get_type()) {
892  case kTINYINT:
894  break;
895  case kINT:
896  constval.intval = (int32_t)constval.floatval;
897  break;
898  case kSMALLINT:
900  break;
901  case kBIGINT:
902  constval.bigintval = (int64_t)constval.floatval;
903  break;
904  case kDOUBLE:
906  break;
907  case kFLOAT:
908  break;
909  case kNUMERIC:
910  case kDECIMAL:
911  for (int i = 0; i < new_type_info.get_scale(); i++) {
912  constval.floatval *= 10;
913  }
914  constval.bigintval = (int64_t)constval.floatval;
915  break;
916  default:
917  CHECK(false);
918  }
919  break;
920  case kNUMERIC:
921  case kDECIMAL:
922  switch (new_type_info.get_type()) {
923  case kTINYINT:
924  for (int i = 0; i < type_info.get_scale(); i++) {
925  constval.bigintval /= 10;
926  }
927  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
928  break;
929  case kINT:
930  for (int i = 0; i < type_info.get_scale(); i++) {
931  constval.bigintval /= 10;
932  }
933  constval.intval = safe_narrow<int32_t>(constval.bigintval);
934  break;
935  case kSMALLINT:
936  for (int i = 0; i < type_info.get_scale(); i++) {
937  constval.bigintval /= 10;
938  }
940  break;
941  case kBIGINT:
942  for (int i = 0; i < type_info.get_scale(); i++) {
943  constval.bigintval /= 10;
944  }
945  break;
946  case kDOUBLE: {
947  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
948  constval.doubleval = int_frac.integral +
949  static_cast<double>(int_frac.fractional) / int_frac.scale;
950  break;
951  }
952  case kFLOAT: {
953  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
954  constval.floatval = int_frac.integral +
955  static_cast<double>(int_frac.fractional) / int_frac.scale;
956  break;
957  }
958  case kNUMERIC:
959  case kDECIMAL:
961  constval.bigintval, type_info, new_type_info);
962  break;
963  default:
964  CHECK(false);
965  }
966  break;
967  case kTIMESTAMP:
968  switch (new_type_info.get_type()) {
969  case kTINYINT:
970  constval.tinyintval = static_cast<int8_t>(constval.bigintval);
971  break;
972  case kINT:
973  constval.intval = static_cast<int32_t>(constval.bigintval);
974  break;
975  case kSMALLINT:
976  constval.smallintval = static_cast<int16_t>(constval.bigintval);
977  break;
978  case kBIGINT:
979  constval.bigintval = static_cast<int64_t>(constval.bigintval);
980  break;
981  case kDOUBLE:
982  constval.doubleval = static_cast<double>(constval.bigintval);
983  break;
984  case kFLOAT:
985  constval.floatval = static_cast<float>(constval.bigintval);
986  break;
987  case kNUMERIC:
988  case kDECIMAL:
989  for (int i = 0; i < new_type_info.get_scale(); i++) {
990  constval.bigintval *= 10;
991  }
992  break;
993  default:
994  CHECK(false);
995  }
996  break;
997  case kBOOLEAN:
998  switch (new_type_info.get_type()) {
999  case kTINYINT:
1000  constval.tinyintval = constval.boolval ? 1 : 0;
1001  break;
1002  case kINT:
1003  constval.intval = constval.boolval ? 1 : 0;
1004  break;
1005  case kSMALLINT:
1007  break;
1008  case kBIGINT:
1009  constval.bigintval = constval.boolval ? 1 : 0;
1010  break;
1011  case kDOUBLE:
1012  constval.doubleval = constval.boolval ? 1 : 0;
1013  break;
1014  case kFLOAT:
1015  constval.floatval = constval.boolval ? 1 : 0;
1016  break;
1017  case kNUMERIC:
1018  case kDECIMAL:
1019  constval.bigintval = constval.boolval ? 1 : 0;
1020  for (int i = 0; i < new_type_info.get_scale(); i++) {
1021  constval.bigintval *= 10;
1022  }
1023  break;
1024  default:
1025  CHECK(false);
1026  }
1027  break;
1028  default:
1029  CHECK(false);
1030  }
1031  type_info = new_type_info;
1032 }
int8_t tinyintval
Definition: sqltypes.h:126
bool boolval
Definition: sqltypes.h:125
HOST DEVICE int get_scale() const
Definition: sqltypes.h:331
SQLTypeInfo type_info
Definition: Analyzer.h:176
int32_t intval
Definition: sqltypes.h:128
float floatval
Definition: sqltypes.h:130
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
int64_t bigintval
Definition: sqltypes.h:129
int16_t smallintval
Definition: sqltypes.h:127
IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:710
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:284
Definition: sqltypes.h:48
double doubleval
Definition: sqltypes.h:131

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

References constval, SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), kTEXT, Datum::stringval, and Analyzer::Expr::type_info.

Referenced by do_cast().

1034  {
1035  std::string* s = constval.stringval;
1036  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1037  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1038  // truncate string
1039  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1040  delete s;
1041  }
1042  type_info = new_type_info;
1043 }
SQLTypeInfo type_info
Definition: Analyzer.h:176
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
std::string * stringval
Definition: sqltypes.h:134
Definition: sqltypes.h:55
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:328

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

References constval, DatumToString(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), kTEXT, Datum::stringval, and Analyzer::Expr::type_info.

Referenced by do_cast().

1053  {
1054  const auto str_val = DatumToString(constval, type_info);
1055  constval.stringval = new std::string(str_val);
1056  if (str_type_info.get_type() != kTEXT &&
1057  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1058  // truncate the string
1059  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1060  }
1061  type_info = str_type_info;
1062 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:193
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::string * stringval
Definition: sqltypes.h:134
Definition: sqltypes.h:55

+ 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, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), is_null, SQLTypeInfoCore< TYPE_FACET_PACK >::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 }
SQLTypeInfo type_info
Definition: Analyzer.h:176
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:342
bool is_geometry() const
Definition: sqltypes.h:489
std::string * stringval
Definition: sqltypes.h:134
bool is_string() const
Definition: sqltypes.h:477

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

References Datum::bigintval, cast_from_string(), cast_number(), cast_string(), cast_to_string(), constval, DateTruncate(), DateTruncateAlterPrecisionScaleDown(), DateTruncateAlterPrecisionScaleUp(), DateTruncateHighPrecisionToDate(), dtDAY, SQLTypeInfoCore< TYPE_FACET_PACK >::get_dimension(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), get_is_null(), DateTimeUtils::get_timestamp_precision_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_boolean(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), is_null, SQLTypeInfoCore< TYPE_FACET_PACK >::is_number(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_time(), kBOOLEAN, kDATE, kTIMESTAMP, kVARCHAR, set_null_value(), Analyzer::Expr::type_info, and value_list.

Referenced by add_cast().

1064  {
1065  if (type_info == new_type_info) {
1066  return;
1067  }
1068  if (is_null) {
1069  type_info = new_type_info;
1070  set_null_value();
1071  return;
1072  }
1073  if (new_type_info.is_number() &&
1075  type_info.get_type() == kBOOLEAN)) {
1076  cast_number(new_type_info);
1077  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1078  type_info = new_type_info;
1079  } else if (new_type_info.is_geometry() &&
1080  type_info.get_type() == new_type_info.get_type()) {
1081  type_info = new_type_info;
1082  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1083  type_info = new_type_info;
1084  } else if (new_type_info.is_string() && type_info.is_string()) {
1085  cast_string(new_type_info);
1086  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1087  cast_from_string(new_type_info);
1088  } else if (new_type_info.is_string()) {
1089  cast_to_string(new_type_info);
1090  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1091  type_info = new_type_info;
1092  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1094  type_info.is_high_precision_timestamp()
1098  : DateTruncate(dtDAY, constval.bigintval);
1099  type_info = new_type_info;
1100  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1101  new_type_info.get_type() == kTIMESTAMP) {
1102  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1103  if (dimen != new_type_info.get_dimension()) {
1104  constval.bigintval = dimen < new_type_info.get_dimension()
1108  new_type_info.get_dimension() - dimen))
1110  constval.bigintval,
1111  DateTimeUtils::get_timestamp_precision_scale(
1112  dimen - new_type_info.get_dimension()));
1113  }
1114  type_info = new_type_info;
1115  } else if (new_type_info.is_array() && type_info.is_array()) {
1116  auto new_sub_ti = new_type_info.get_elem_type();
1117  for (auto& v : value_list) {
1118  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1119  if (!c) {
1120  throw std::runtime_error("Invalid array cast.");
1121  }
1122  c->do_cast(new_sub_ti);
1123  }
1124  type_info = new_type_info;
1125  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1126  new_type_info.is_string())) {
1127  type_info = new_type_info;
1128  set_null_value();
1129  } else {
1130  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1131  new_type_info.get_type_name() + " not supported");
1132  }
1133 }
bool is_boolean() const
Definition: sqltypes.h:484
NEVER_INLINE DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool get_is_null() const
Definition: Analyzer.h:328
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1045
DEVICE int64_t DateTruncateAlterPrecisionScaleUp(const int64_t timeval, const int64_t scale)
SQLTypeInfo type_info
Definition: Analyzer.h:176
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1034
bool is_number() const
Definition: sqltypes.h:482
std::string get_type_name() const
Definition: sqltypes.h:429
bool is_array() const
Definition: sqltypes.h:485
DEVICE int64_t DateTruncateAlterPrecisionScaleDown(const int64_t timeval, const int64_t scale)
bool is_time() const
Definition: sqltypes.h:483
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
int64_t bigintval
Definition: sqltypes.h:129
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:342
bool is_geometry() const
Definition: sqltypes.h:489
Definition: sqltypes.h:56
DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:328
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:739
bool is_string() const
Definition: sqltypes.h:477
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:48
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1053
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Analyzer::Constant::get_is_null ( ) const
inline
const std::list<std::shared_ptr<Analyzer::Expr> >& Analyzer::Constant::get_value_list ( ) const
inline

Definition at line 331 of file Analyzer.h.

References value_list.

Referenced by CgenState::getOrAddLiteral().

331  {
332  return value_list;
333  }
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:342

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2014 of file Analyzer.cpp.

References constval, Analyzer::Datum_equal(), get_constval(), get_is_null(), Analyzer::Expr::get_type_info(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), is_null, and Analyzer::Expr::type_info.

2014  {
2015  if (typeid(rhs) != typeid(Constant)) {
2016  return false;
2017  }
2018  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2019  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2020  return false;
2021  }
2022  if (is_null && rhs_c.get_is_null()) {
2023  return true;
2024  }
2025  if (type_info.is_array()) {
2026  return false;
2027  }
2028  return Datum_equal(type_info, constval, rhs_c.get_constval());
2029 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:1973
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool is_array() const
Definition: sqltypes.h:485

+ Here is the call graph for this function:

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

Definition at line 330 of file Analyzer.h.

References constval.

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

Definition at line 1135 of file Analyzer.cpp.

References Datum::arrayval, Datum::bigintval, Datum::boolval, CHECK(), constval, Datum::doubleval, Datum::floatval, SQLTypeInfoCore< TYPE_FACET_PACK >::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().

1135  {
1136  switch (type_info.get_type()) {
1137  case kBOOLEAN:
1139  break;
1140  case kTINYINT:
1142  break;
1143  case kINT:
1145  break;
1146  case kSMALLINT:
1148  break;
1149  case kBIGINT:
1150  case kNUMERIC:
1151  case kDECIMAL:
1153  break;
1154  case kTIME:
1155  case kTIMESTAMP:
1156  case kDATE:
1158  break;
1159  case kVARCHAR:
1160  case kCHAR:
1161  case kTEXT:
1162  constval.stringval = nullptr;
1163  break;
1164  case kPOINT:
1165  case kLINESTRING:
1166  case kPOLYGON:
1167  case kMULTIPOLYGON:
1168  constval.stringval = nullptr;
1169  break;
1170  case kFLOAT:
1172  break;
1173  case kDOUBLE:
1175  break;
1176  case kNULLT:
1177  constval.bigintval = 0;
1178  break;
1179  case kARRAY:
1180  constval.arrayval = nullptr;
1181  break;
1182  default:
1183  CHECK(false);
1184  }
1185 }
int8_t tinyintval
Definition: sqltypes.h:126
#define NULL_DOUBLE
Definition: sqltypes.h:179
Definition: sqltypes.h:52
#define NULL_BIGINT
Definition: sqltypes.h:177
bool boolval
Definition: sqltypes.h:125
VarlenDatum * arrayval
Definition: sqltypes.h:132
SQLTypeInfo type_info
Definition: Analyzer.h:176
int32_t intval
Definition: sqltypes.h:128
float floatval
Definition: sqltypes.h:130
CHECK(cgen_state)
#define NULL_TINYINT
Definition: sqltypes.h:174
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
int64_t bigintval
Definition: sqltypes.h:129
#define NULL_FLOAT
Definition: sqltypes.h:178
int16_t smallintval
Definition: sqltypes.h:127
#define NULL_INT
Definition: sqltypes.h:176
std::string * stringval
Definition: sqltypes.h:134
Definition: sqltypes.h:55
Definition: sqltypes.h:56
Definition: sqltypes.h:44
#define NULL_SMALLINT
Definition: sqltypes.h:175
Definition: sqltypes.h:48
#define NULL_BOOLEAN
Definition: sqltypes.h:173
double doubleval
Definition: sqltypes.h:131

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

References constval, DatumToString(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), is_null, sql_type_to_str(), and Analyzer::Expr::type_info.

2303  {
2304  std::string str{"(Const "};
2305  if (is_null) {
2306  str += "NULL";
2307  } else if (type_info.is_array()) {
2308  const auto& elem_ti = type_info.get_elem_type();
2309  str += sql_type_to_str(type_info.get_type()) + ": " +
2310  sql_type_to_str(elem_ti.get_type());
2311  } else {
2312  str += DatumToString(constval, type_info);
2313  }
2314  str += ") ";
2315  return str;
2316 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:193
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool is_array() const
Definition: sqltypes.h:485
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
std::string sql_type_to_str(const SQLTypes &type)
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659

+ Here is the call graph for this function:

Member Data Documentation

bool Analyzer::Constant::is_null
private

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