OmniSciDB  c07336695a
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 ()
 
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::Exprnormalize_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::Exprrewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual std::shared_ptr< Analyzer::Exprrewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual std::shared_ptr< Analyzer::Exprrewrite_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 305 of file Analyzer.h.

Constructor & Destructor Documentation

◆ Constant() [1/4]

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

Definition at line 307 of file Analyzer.h.

Referenced by Analyzer::Expr::add_cast().

307  : Expr(t, !n), is_null(n) {
308  if (n) {
309  set_null_value();
310  }
311  }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
+ Here is the caller graph for this function:

◆ Constant() [2/4]

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

Definition at line 312 of file Analyzer.h.

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

◆ Constant() [3/4]

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

Definition at line 317 of file Analyzer.h.

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

◆ Constant() [4/4]

Analyzer::Constant::Constant ( const SQLTypeInfo ti,
bool  n,
const std::list< std::shared_ptr< Analyzer::Expr >> &  l 
)
inline

Definition at line 322 of file Analyzer.h.

325  : 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:341

◆ ~Constant()

Analyzer::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:175
std::string * stringval
Definition: sqltypes.h:131
bool is_geometry() const
Definition: sqltypes.h:458
bool is_string() const
Definition: sqltypes.h:446
+ Here is the call graph for this function:

Member Function Documentation

◆ add_cast()

std::shared_ptr< Analyzer::Expr > Analyzer::Constant::add_cast ( const SQLTypeInfo new_type_info)
overridevirtual

Reimplemented from Analyzer::Expr.

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

1179  {
1180  if (is_null) {
1181  type_info = new_type_info;
1182  set_null_value();
1183  return shared_from_this();
1184  }
1185  if (new_type_info.get_compression() != type_info.get_compression()) {
1186  if (new_type_info.get_compression() != kENCODING_NONE) {
1187  SQLTypeInfo new_ti = new_type_info;
1188  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1190  }
1191  do_cast(new_ti);
1192  }
1193  return Expr::add_cast(new_type_info);
1194  }
1195  if (is_member_of_typeset<kINT, kDECIMAL, kFLOAT, kDOUBLE>(new_type_info) &&
1196  is_member_of_typeset<kTIME, kDATE>(type_info)) {
1197  // Let the codegen phase deal with casts from date/time to a number.
1198  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1199  }
1200  do_cast(new_type_info);
1201  return shared_from_this();
1202 }
Definition: sqldefs.h:49
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:327
void set_compression(EncodingType c)
Definition: sqltypes.h:419
SQLTypeInfo type_info
Definition: Analyzer.h:175
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1056
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:663
bool contains_agg
Definition: Analyzer.h:176
+ Here is the call graph for this function:

◆ cast_from_string()

void Analyzer::Constant::cast_from_string ( const SQLTypeInfo new_type_info)
private

Definition at line 1037 of file Analyzer.cpp.

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

Referenced by do_cast().

1037  {
1038  std::string* s = constval.stringval;
1039  SQLTypeInfo ti = new_type_info;
1040  constval = StringToDatum(*s, ti);
1041  delete s;
1042  type_info = new_type_info;
1043 }
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string * stringval
Definition: sqltypes.h:131
Datum StringToDatum(const std::string &s, SQLTypeInfo &ti)
Definition: Datum.cpp:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cast_number()

void Analyzer::Constant::cast_number ( const SQLTypeInfo new_type_info)
private

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

731  {
732  switch (type_info.get_type()) {
733  case kTINYINT:
734  switch (new_type_info.get_type()) {
735  case kTINYINT:
736  break;
737  case kINT:
738  constval.intval = (int32_t)constval.tinyintval;
739  break;
740  case kSMALLINT:
742  break;
743  case kBIGINT:
745  break;
746  case kDOUBLE:
748  break;
749  case kFLOAT:
751  break;
752  case kNUMERIC:
753  case kDECIMAL:
755  for (int i = 0; i < new_type_info.get_scale(); i++) {
756  constval.bigintval *= 10;
757  }
758  break;
759  default:
760  CHECK(false);
761  }
762  break;
763  case kINT:
764  switch (new_type_info.get_type()) {
765  case kTINYINT:
766  constval.tinyintval = safe_narrow<int8_t>(constval.intval);
767  break;
768  case kINT:
769  break;
770  case kSMALLINT:
771  constval.smallintval = safe_narrow<int16_t>(constval.intval);
772  break;
773  case kBIGINT:
774  constval.bigintval = (int64_t)constval.intval;
775  break;
776  case kDOUBLE:
777  constval.doubleval = (double)constval.intval;
778  break;
779  case kFLOAT:
780  constval.floatval = (float)constval.intval;
781  break;
782  case kNUMERIC:
783  case kDECIMAL:
784  constval.bigintval = (int64_t)constval.intval;
785  for (int i = 0; i < new_type_info.get_scale(); i++) {
786  constval.bigintval *= 10;
787  }
788  break;
789  default:
790  CHECK(false);
791  }
792  break;
793  case kSMALLINT:
794  switch (new_type_info.get_type()) {
795  case kTINYINT:
796  constval.tinyintval = safe_narrow<int8_t>(constval.smallintval);
797  break;
798  case kINT:
799  constval.intval = (int32_t)constval.smallintval;
800  break;
801  case kSMALLINT:
802  break;
803  case kBIGINT:
805  break;
806  case kDOUBLE:
808  break;
809  case kFLOAT:
811  break;
812  case kNUMERIC:
813  case kDECIMAL:
815  for (int i = 0; i < new_type_info.get_scale(); i++) {
816  constval.bigintval *= 10;
817  }
818  break;
819  default:
820  CHECK(false);
821  }
822  break;
823  case kBIGINT:
824  switch (new_type_info.get_type()) {
825  case kTINYINT:
826  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
827  break;
828  case kINT:
829  constval.intval = safe_narrow<int32_t>(constval.bigintval);
830  break;
831  case kSMALLINT:
832  constval.smallintval = safe_narrow<int16_t>(constval.bigintval);
833  break;
834  case kBIGINT:
835  break;
836  case kDOUBLE:
838  break;
839  case kFLOAT:
841  break;
842  case kNUMERIC:
843  case kDECIMAL:
844  for (int i = 0; i < new_type_info.get_scale(); i++) {
845  constval.bigintval *= 10;
846  }
847  break;
848  default:
849  CHECK(false);
850  }
851  break;
852  case kDOUBLE:
853  switch (new_type_info.get_type()) {
854  case kTINYINT:
856  break;
857  case kINT:
858  constval.intval = (int32_t)constval.doubleval;
859  break;
860  case kSMALLINT:
862  break;
863  case kBIGINT:
865  break;
866  case kDOUBLE:
867  break;
868  case kFLOAT:
870  break;
871  case kNUMERIC:
872  case kDECIMAL:
873  for (int i = 0; i < new_type_info.get_scale(); i++) {
874  constval.doubleval *= 10;
875  }
877  break;
878  default:
879  CHECK(false);
880  }
881  break;
882  case kFLOAT:
883  switch (new_type_info.get_type()) {
884  case kTINYINT:
886  break;
887  case kINT:
888  constval.intval = (int32_t)constval.floatval;
889  break;
890  case kSMALLINT:
892  break;
893  case kBIGINT:
894  constval.bigintval = (int64_t)constval.floatval;
895  break;
896  case kDOUBLE:
898  break;
899  case kFLOAT:
900  break;
901  case kNUMERIC:
902  case kDECIMAL:
903  for (int i = 0; i < new_type_info.get_scale(); i++) {
904  constval.floatval *= 10;
905  }
906  constval.bigintval = (int64_t)constval.floatval;
907  break;
908  default:
909  CHECK(false);
910  }
911  break;
912  case kNUMERIC:
913  case kDECIMAL:
914  switch (new_type_info.get_type()) {
915  case kTINYINT:
916  for (int i = 0; i < type_info.get_scale(); i++) {
917  constval.bigintval /= 10;
918  }
919  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
920  break;
921  case kINT:
922  for (int i = 0; i < type_info.get_scale(); i++) {
923  constval.bigintval /= 10;
924  }
925  constval.intval = safe_narrow<int32_t>(constval.bigintval);
926  break;
927  case kSMALLINT:
928  for (int i = 0; i < type_info.get_scale(); i++) {
929  constval.bigintval /= 10;
930  }
932  break;
933  case kBIGINT:
934  for (int i = 0; i < type_info.get_scale(); i++) {
935  constval.bigintval /= 10;
936  }
937  break;
938  case kDOUBLE: {
939  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
940  constval.doubleval = int_frac.integral +
941  static_cast<double>(int_frac.fractional) / int_frac.scale;
942  break;
943  }
944  case kFLOAT: {
945  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
946  constval.floatval = int_frac.integral +
947  static_cast<double>(int_frac.fractional) / int_frac.scale;
948  break;
949  }
950  case kNUMERIC:
951  case kDECIMAL:
953  constval.bigintval, type_info, new_type_info);
954  break;
955  default:
956  CHECK(false);
957  }
958  break;
959  case kTIMESTAMP:
960  switch (new_type_info.get_type()) {
961  case kTINYINT:
962  constval.tinyintval = static_cast<int8_t>(constval.bigintval);
963  break;
964  case kINT:
965  constval.intval = static_cast<int32_t>(constval.bigintval);
966  break;
967  case kSMALLINT:
968  constval.smallintval = static_cast<int16_t>(constval.bigintval);
969  break;
970  case kBIGINT:
971  constval.bigintval = static_cast<int64_t>(constval.bigintval);
972  break;
973  case kDOUBLE:
974  constval.doubleval = static_cast<double>(constval.bigintval);
975  break;
976  case kFLOAT:
977  constval.floatval = static_cast<float>(constval.bigintval);
978  break;
979  case kNUMERIC:
980  case kDECIMAL:
981  for (int i = 0; i < new_type_info.get_scale(); i++) {
982  constval.bigintval *= 10;
983  }
984  break;
985  default:
986  CHECK(false);
987  }
988  break;
989  case kBOOLEAN:
990  switch (new_type_info.get_type()) {
991  case kTINYINT:
993  break;
994  case kINT:
995  constval.intval = constval.boolval ? 1 : 0;
996  break;
997  case kSMALLINT:
999  break;
1000  case kBIGINT:
1001  constval.bigintval = constval.boolval ? 1 : 0;
1002  break;
1003  case kDOUBLE:
1004  constval.doubleval = constval.boolval ? 1 : 0;
1005  break;
1006  case kFLOAT:
1007  constval.floatval = constval.boolval ? 1 : 0;
1008  break;
1009  case kNUMERIC:
1010  case kDECIMAL:
1011  constval.bigintval = constval.boolval ? 1 : 0;
1012  for (int i = 0; i < new_type_info.get_scale(); i++) {
1013  constval.bigintval *= 10;
1014  }
1015  break;
1016  default:
1017  CHECK(false);
1018  }
1019  break;
1020  default:
1021  CHECK(false);
1022  }
1023  type_info = new_type_info;
1024 }
int8_t tinyintval
Definition: sqltypes.h:123
bool boolval
Definition: sqltypes.h:122
HOST DEVICE int get_scale() const
Definition: sqltypes.h:324
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
SQLTypeInfo type_info
Definition: Analyzer.h:175
int32_t intval
Definition: sqltypes.h:125
float floatval
Definition: sqltypes.h:127
int64_t bigintval
Definition: sqltypes.h:126
int16_t smallintval
Definition: sqltypes.h:124
IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:702
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:432
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
double doubleval
Definition: sqltypes.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cast_string()

void Analyzer::Constant::cast_string ( const SQLTypeInfo new_type_info)
private

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

1026  {
1027  std::string* s = constval.stringval;
1028  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1029  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1030  // truncate string
1031  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1032  delete s;
1033  }
1034  type_info = new_type_info;
1035 }
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string * stringval
Definition: sqltypes.h:131
Definition: sqltypes.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cast_to_string()

void Analyzer::Constant::cast_to_string ( const SQLTypeInfo new_type_info)
private

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

1045  {
1046  const auto str_val = DatumToString(constval, type_info);
1047  constval.stringval = new std::string(str_val);
1048  if (str_type_info.get_type() != kTEXT &&
1049  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1050  // truncate the string
1051  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1052  }
1053  type_info = str_type_info;
1054 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:341
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::string * stringval
Definition: sqltypes.h:131
Definition: sqltypes.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deep_copy()

std::shared_ptr< Analyzer::Expr > Analyzer::Constant::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 84 of file Analyzer.cpp.

References constval, anonymous_namespace{ImportTest.cpp}::d(), 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 Analyzer::BinOper::normalize_simple_predicate(), and 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 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
SQLTypeInfo type_info
Definition: Analyzer.h:175
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:341
std::string * stringval
Definition: sqltypes.h:131
bool is_geometry() const
Definition: sqltypes.h:458
bool is_string() const
Definition: sqltypes.h:446
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_cast()

void Analyzer::Constant::do_cast ( const SQLTypeInfo new_type_info)
private

Definition at line 1056 of file Analyzer.cpp.

References Datum::bigintval, anonymous_namespace{ExecuteTest.cpp}::c(), 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, v(), and value_list.

Referenced by add_cast().

1056  {
1057  if (type_info == new_type_info) {
1058  return;
1059  }
1060  if (is_null) {
1061  type_info = new_type_info;
1062  set_null_value();
1063  return;
1064  }
1065  if (new_type_info.is_number() &&
1067  type_info.get_type() == kBOOLEAN)) {
1068  cast_number(new_type_info);
1069  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1070  type_info = new_type_info;
1071  } else if (new_type_info.is_geometry() &&
1072  type_info.get_type() == new_type_info.get_type()) {
1073  type_info = new_type_info;
1074  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1075  type_info = new_type_info;
1076  } else if (new_type_info.is_string() && type_info.is_string()) {
1077  cast_string(new_type_info);
1078  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1079  cast_from_string(new_type_info);
1080  } else if (new_type_info.is_string()) {
1081  cast_to_string(new_type_info);
1082  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1083  type_info = new_type_info;
1084  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1086  type_info.is_high_precision_timestamp()
1090  : DateTruncate(dtDAY, constval.bigintval);
1091  type_info = new_type_info;
1092  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1093  new_type_info.get_type() == kTIMESTAMP) {
1094  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1095  if (dimen != new_type_info.get_dimension()) {
1096  constval.bigintval = dimen < new_type_info.get_dimension()
1100  new_type_info.get_dimension() - dimen))
1102  constval.bigintval,
1104  dimen - new_type_info.get_dimension()));
1105  }
1106  type_info = new_type_info;
1107  } else if (new_type_info.is_array() && type_info.is_array()) {
1108  auto new_sub_ti = new_type_info.get_elem_type();
1109  for (auto& v : value_list) {
1110  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1111  if (!c) {
1112  throw std::runtime_error("Invalid array cast.");
1113  }
1114  c->do_cast(new_sub_ti);
1115  }
1116  type_info = new_type_info;
1117  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1118  new_type_info.is_string())) {
1119  type_info = new_type_info;
1120  set_null_value();
1121  } else {
1122  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1123  new_type_info.get_type_name() + " not supported");
1124  }
1125 }
NEVER_INLINE DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)
bool is_time() const
Definition: sqltypes.h:452
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:321
void c(const std::string &query_string, const ExecutorDeviceType device_type)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
DEVICE int64_t DateTruncateAlterPrecisionScaleUp(const int64_t timeval, const int64_t scale)
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:731
SQLTypeInfo type_info
Definition: Analyzer.h:175
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1037
std::string get_type_name() const
Definition: sqltypes.h:422
bool is_array() const
Definition: sqltypes.h:454
T v(const TargetValue &r)
DEVICE int64_t DateTruncateAlterPrecisionScaleDown(const int64_t timeval, const int64_t scale)
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1026
int64_t bigintval
Definition: sqltypes.h:126
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:341
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:628
bool is_boolean() const
Definition: sqltypes.h:453
bool get_is_null() const
Definition: Analyzer.h:327
Definition: sqltypes.h:55
DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
bool is_number() const
Definition: sqltypes.h:451
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:48
bool is_geometry() const
Definition: sqltypes.h:458
bool is_string() const
Definition: sqltypes.h:446
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1045
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_constval()

◆ get_is_null()

bool Analyzer::Constant::get_is_null ( ) const
inline

Definition at line 327 of file Analyzer.h.

References anonymous_namespace{TypedDataAccessors.h}::is_null().

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenIntConst(), Parser::InsertValuesStmt::determineLeafIndex(), do_cast(), Parser::anonymous_namespace{ParserNode.cpp}::expr_is_null(), getExpressionRange(), CgenState::getOrAddLiteral(), anonymous_namespace{Execute.cpp}::insert_one_dict_str(), Analyzer::anonymous_namespace{Analyzer.cpp}::is_expr_nullable(), anonymous_namespace{WindowExpressionRewrite.cpp}::matches_else_null(), and operator==().

327 { return is_null; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_value_list()

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

Definition at line 330 of file Analyzer.h.

References operator==().

Referenced by CgenState::getOrAddLiteral().

330  {
331  return value_list;
332  }
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:341
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator==()

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

Implements Analyzer::Expr.

Definition at line 1992 of file Analyzer.cpp.

References Analyzer::Datum_equal(), get_constval(), get_is_null(), Analyzer::Expr::get_type_info(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), anonymous_namespace{TypedDataAccessors.h}::is_null(), and Analyzer::Expr::type_info.

1992  {
1993  if (typeid(rhs) != typeid(Constant)) {
1994  return false;
1995  }
1996  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
1997  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
1998  return false;
1999  }
2000  if (is_null && rhs_c.get_is_null()) {
2001  return true;
2002  }
2003  if (type_info.is_array()) {
2004  return false;
2005  }
2006  return Datum_equal(type_info, constval, rhs_c.get_constval());
2007 }
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:1951
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool is_array() const
Definition: sqltypes.h:454
Constant(SQLTypes t, bool n)
Definition: Analyzer.h:307
+ Here is the call graph for this function:

◆ set_constval()

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

Definition at line 329 of file Analyzer.h.

References anonymous_namespace{ImportTest.cpp}::d().

329 { constval = d; }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
+ Here is the call graph for this function:

◆ set_null_value()

void Analyzer::Constant::set_null_value ( )
private

Definition at line 1127 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(), and do_cast().

1127  {
1128  switch (type_info.get_type()) {
1129  case kBOOLEAN:
1131  break;
1132  case kTINYINT:
1134  break;
1135  case kINT:
1137  break;
1138  case kSMALLINT:
1140  break;
1141  case kBIGINT:
1142  case kNUMERIC:
1143  case kDECIMAL:
1145  break;
1146  case kTIME:
1147  case kTIMESTAMP:
1148  case kDATE:
1150  break;
1151  case kVARCHAR:
1152  case kCHAR:
1153  case kTEXT:
1154  constval.stringval = nullptr;
1155  break;
1156  case kPOINT:
1157  case kLINESTRING:
1158  case kPOLYGON:
1159  case kMULTIPOLYGON:
1160  constval.stringval = nullptr;
1161  break;
1162  case kFLOAT:
1164  break;
1165  case kDOUBLE:
1167  break;
1168  case kNULLT:
1169  constval.bigintval = 0;
1170  break;
1171  case kARRAY:
1172  constval.arrayval = nullptr;
1173  break;
1174  default:
1175  CHECK(false);
1176  }
1177 }
int8_t tinyintval
Definition: sqltypes.h:123
#define NULL_DOUBLE
Definition: sqltypes.h:177
Definition: sqltypes.h:51
#define NULL_BIGINT
Definition: sqltypes.h:175
bool boolval
Definition: sqltypes.h:122
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
VarlenDatum * arrayval
Definition: sqltypes.h:129
SQLTypeInfo type_info
Definition: Analyzer.h:175
int32_t intval
Definition: sqltypes.h:125
float floatval
Definition: sqltypes.h:127
#define NULL_TINYINT
Definition: sqltypes.h:172
int64_t bigintval
Definition: sqltypes.h:126
#define NULL_FLOAT
Definition: sqltypes.h:176
int16_t smallintval
Definition: sqltypes.h:124
#define NULL_INT
Definition: sqltypes.h:174
std::string * stringval
Definition: sqltypes.h:131
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
#define NULL_SMALLINT
Definition: sqltypes.h:173
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
#define NULL_BOOLEAN
Definition: sqltypes.h:171
double doubleval
Definition: sqltypes.h:128
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

std::string Analyzer::Constant::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2262 of file Analyzer.cpp.

References DatumToString(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), anonymous_namespace{TypedDataAccessors.h}::is_null(), sql_type_to_str(), and Analyzer::Expr::type_info.

2262  {
2263  std::string str{"(Const "};
2264  if (is_null) {
2265  str += "NULL";
2266  } else if (type_info.is_array()) {
2267  const auto& elem_ti = type_info.get_elem_type();
2268  str += sql_type_to_str(type_info.get_type()) + ": " +
2269  sql_type_to_str(elem_ti.get_type());
2270  } else {
2271  str += DatumToString(constval, type_info);
2272  }
2273  str += ") ";
2274  return str;
2275 }
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:341
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:319
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool is_array() const
Definition: sqltypes.h:454
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:628
std::string sql_type_to_str(const SQLTypes &type)
+ Here is the call graph for this function:

Member Data Documentation

◆ constval

Datum Analyzer::Constant::constval
private

◆ is_null

bool Analyzer::Constant::is_null
private

Definition at line 339 of file Analyzer.h.

Referenced by add_cast(), deep_copy(), do_cast(), and ~Constant().

◆ value_list

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

Definition at line 341 of file Analyzer.h.

Referenced by deep_copy(), Analyzer::InValues::deep_copy(), and do_cast().


The documentation for this class was generated from the following files: