OmniSciDB  85c2d10cdc
 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 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 39 of file Analyzer.cpp.

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

39  {
40  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
41  delete constval.stringval;
42  }
43 }
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::string * stringval
Definition: sqltypes.h:214
bool is_geometry() const
Definition: sqltypes.h:500
bool is_string() const
Definition: sqltypes.h:488

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

1259  {
1260  if (is_null) {
1261  type_info = new_type_info;
1262  set_null_value();
1263  return shared_from_this();
1264  }
1265  if (new_type_info.get_compression() != type_info.get_compression()) {
1266  if (new_type_info.get_compression() != kENCODING_NONE) {
1267  SQLTypeInfo new_ti = new_type_info;
1268  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1270  }
1271  do_cast(new_ti);
1272  }
1273  return Expr::add_cast(new_type_info);
1274  }
1275  const auto is_integral_type =
1276  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1277  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1278  // Let the codegen phase deal with casts from date/time to a number.
1279  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1280  }
1281  do_cast(new_type_info);
1282  return shared_from_this();
1283 }
void set_compression(EncodingType c)
Definition: sqltypes.h:414
bool is_fp() const
Definition: sqltypes.h:492
Definition: sqldefs.h:49
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool is_time() const
Definition: sqltypes.h:494
bool is_integer() const
Definition: sqltypes.h:490
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1130
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:687
bool contains_agg
Definition: Analyzer.h:177
bool is_decimal() const
Definition: sqltypes.h:491
bool is_date() const
Definition: sqltypes.h:730

+ Here is the call graph for this function:

void Constant::cast_from_string ( const SQLTypeInfo new_type_info)
private

Definition at line 1061 of file Analyzer.cpp.

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

Referenced by do_cast().

1061  {
1062  std::string* s = constval.stringval;
1063  SQLTypeInfo ti = new_type_info;
1064  constval = StringToDatum(*s, ti);
1065  delete s;
1066  type_info = new_type_info;
1067 }
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)
private

Definition at line 755 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(), i, 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().

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

Definition at line 1050 of file Analyzer.cpp.

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

Referenced by do_cast().

1050  {
1051  std::string* s = constval.stringval;
1052  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1053  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1054  // truncate string
1055  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1056  delete s;
1057  }
1058  type_info = new_type_info;
1059 }
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)
private

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

1069  {
1070  const auto str_val = DatumToString(constval, type_info);
1071  constval.stringval = new std::string(str_val);
1072  if (str_type_info.get_type() != kTEXT &&
1073  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1074  // truncate the string
1075  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1076  }
1077  type_info = str_type_info;
1078 }
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 82 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().

82  {
83  Datum d = constval;
84  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
85  d.stringval = new std::string(*constval.stringval);
86  }
87  if (type_info.get_type() == kARRAY) {
88  return makeExpr<Constant>(type_info, is_null, value_list);
89  }
90  return makeExpr<Constant>(type_info, is_null, d);
91 }
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:500
bool is_string() const
Definition: sqltypes.h:488

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

1130  {
1131  if (type_info == new_type_info) {
1132  return;
1133  }
1134  if (is_null && !new_type_info.get_notnull()) {
1135  type_info = new_type_info;
1136  set_null_value();
1137  return;
1138  }
1139  if (new_type_info.is_number() &&
1141  type_info.get_type() == kBOOLEAN)) {
1142  cast_number(new_type_info);
1143  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1144  type_info = new_type_info;
1145  } else if (new_type_info.is_geometry() &&
1146  type_info.get_type() == new_type_info.get_type()) {
1147  type_info = new_type_info;
1148  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1149  type_info = new_type_info;
1150  } else if (new_type_info.is_string() && type_info.is_string()) {
1151  cast_string(new_type_info);
1152  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1153  cast_from_string(new_type_info);
1154  } else if (new_type_info.is_string()) {
1155  cast_to_string(new_type_info);
1156  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1157  type_info = new_type_info;
1158  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1164  : DateTruncate(dtDAY, constval.bigintval);
1165  type_info = new_type_info;
1166  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1167  new_type_info.get_type() == kTIMESTAMP) {
1168  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1169  if (dimen != new_type_info.get_dimension()) {
1170  constval.bigintval = dimen < new_type_info.get_dimension()
1174  new_type_info.get_dimension() - dimen)
1178  dimen - new_type_info.get_dimension());
1179  }
1180  type_info = new_type_info;
1181  } else if (new_type_info.is_array() && type_info.is_array()) {
1182  auto new_sub_ti = new_type_info.get_elem_type();
1183  for (auto& v : value_list) {
1184  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1185  if (!c) {
1186  throw std::runtime_error("Invalid array cast.");
1187  }
1188  c->do_cast(new_sub_ti);
1189  }
1190  type_info = new_type_info;
1191  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1192  new_type_info.is_string() || new_type_info.is_boolean())) {
1193  type_info = new_type_info;
1194  set_null_value();
1195  } else if (!is_null_value(type_info, constval) &&
1196  get_nullable_type_info(type_info) == new_type_info) {
1197  CHECK(!is_null);
1198  // relax nullability
1199  type_info = new_type_info;
1200  return;
1201  } else {
1202  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1203  new_type_info.get_type_name() + " not supported");
1204  }
1205 }
bool is_null_value(const SQLTypeInfo &ti, const Datum &constval)
Definition: Analyzer.cpp:1086
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:1061
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
bool is_number() const
Definition: sqltypes.h:493
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:494
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1050
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:495
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:755
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
#define CHECK(condition)
Definition: Logger.h:197
bool is_geometry() const
Definition: sqltypes.h:500
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:732
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1069
bool is_string() const
Definition: sqltypes.h:488
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:321
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:712
bool is_array() const
Definition: sqltypes.h:496
SQLTypeInfo get_nullable_type_info(const SQLTypeInfo &type_info)
Definition: sqltypes.h:925

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

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

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

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

1207  {
1208  switch (type_info.get_type()) {
1209  case kBOOLEAN:
1211  break;
1212  case kTINYINT:
1214  break;
1215  case kINT:
1217  break;
1218  case kSMALLINT:
1220  break;
1221  case kBIGINT:
1222  case kNUMERIC:
1223  case kDECIMAL:
1225  break;
1226  case kTIME:
1227  case kTIMESTAMP:
1228  case kDATE:
1230  break;
1231  case kVARCHAR:
1232  case kCHAR:
1233  case kTEXT:
1234  constval.stringval = nullptr;
1235  break;
1236  case kPOINT:
1237  case kLINESTRING:
1238  case kPOLYGON:
1239  case kMULTIPOLYGON:
1240  constval.stringval = nullptr;
1241  break;
1242  case kFLOAT:
1244  break;
1245  case kDOUBLE:
1247  break;
1248  case kNULLT:
1249  constval.bigintval = 0;
1250  break;
1251  case kARRAY:
1252  constval.arrayval = nullptr;
1253  break;
1254  default:
1255  CHECK(false);
1256  }
1257 }
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:197
#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 2423 of file Analyzer.cpp.

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

2423  {
2424  std::string str{"(Const "};
2425  if (is_null) {
2426  str += "NULL";
2427  } else if (type_info.is_array()) {
2428  const auto& elem_ti = type_info.get_elem_type();
2429  str += ::toString(type_info.get_type()) + ": " + ::toString(elem_ti.get_type());
2430  } else {
2431  str += DatumToString(constval, type_info);
2432  }
2433  str += ") ";
2434  return str;
2435 }
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:2423
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:712
bool is_array() const
Definition: sqltypes.h:496

+ Here is the call graph for this function:

Member Data Documentation

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

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: