Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::BoundCastExpression Class Reference
Inheritance diagram for duckdb::BoundCastExpression:
Collaboration diagram for duckdb::BoundCastExpression:

Public Member Functions

 BoundCastExpression (unique_ptr< Expression > child, LogicalType target_type, BoundCastInfo bound_cast, bool try_cast=false)
LogicalType source_type ()
string ToString () const override
 Convert the Expression to a String.
bool Equals (const BaseExpression &other) const override
 Returns true if this expression is equal to another expression.
unique_ptr< Expression > Copy () const override
 Create a copy of this expression.
bool CanThrow () const override
void Serialize (Serializer &serializer) const override
Public Member Functions inherited from duckdb::Expression
 Expression (ExpressionType type, ExpressionClass expression_class, LogicalType return_type)
bool IsAggregate () const override
 Returns true if this expression is an aggregate or not.
bool IsWindow () const override
 Returns true if the expression has a window function or not.
bool HasSubquery () const override
 Returns true if the query contains a subquery.
bool IsScalar () const override
 Returns true if expression does not contain a group ref or col ref or parameter.
bool HasParameter () const override
 Returns true if the expression has a parameter.
virtual bool IsVolatile () const
virtual bool IsConsistent () const
virtual bool PropagatesNullValues () const
virtual bool IsFoldable () const
hash_t Hash () const override
bool Equals (const BaseExpression &other) const override
 Returns true if this expression is equal to another expression.
Public Member Functions inherited from duckdb::BaseExpression
 BaseExpression (ExpressionType type, ExpressionClass expression_class)
 Create an Expression.
ExpressionClass GetExpressionClass () const
 Returns the class of the expression.
ExpressionType GetExpressionType () const
 Returns the type of the expression.
void SetExpressionTypeUnsafe (ExpressionType new_type)
optional_idx GetQueryLocation () const
 Returns the location in the query (if any).
void SetQueryLocation (optional_idx location)
 Sets the location in the query.
bool HasAlias () const
 Returns true if the expression has a non-empty alias.
const string & GetAlias () const
 Returns the alias of the expression.
void SetAlias (const string &alias_p)
 Sets the alias of the expression.
void SetAlias (string &&alias_p)
 Sets the alias of the expression.
void ClearAlias ()
 Clears the alias of the expression.
virtual string GetName () const
 Get the name of the expression.
void Print () const
 Print the expression to stdout.
bool operator== (const BaseExpression &rhs) const
virtual void Verify () const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static unique_ptr< Expression > AddDefaultCastToType (unique_ptr< Expression > expr, const LogicalType &target_type, bool try_cast=false)
 Cast an expression to the specified SQL type, using only the built-in SQL casts.
static DUCKDB_API unique_ptr< Expression > AddCastToType (ClientContext &context, unique_ptr< Expression > expr, const LogicalType &target_type, bool try_cast=false)
 Cast an expression to the specified SQL type if required.
static DUCKDB_API unique_ptr< Expression > AddArrayCastToList (ClientContext &context, unique_ptr< Expression > expr)
 If the expression returns an array, cast it to return a list with the same child type. Otherwise do nothing.
static bool CastIsInvertible (const LogicalType &source_type, const LogicalType &target_type)
static unique_ptr< Expression > Deserialize (Deserializer &deserializer)
Static Public Member Functions inherited from duckdb::Expression
static bool Equals (const Expression &left, const Expression &right)
static bool Equals (const unique_ptr< Expression > &left, const unique_ptr< Expression > &right)
static bool ListEquals (const vector< unique_ptr< Expression > > &left, const vector< unique_ptr< Expression > > &right)
static unique_ptr< Expression > Deserialize (Deserializer &deserializer)
Static Public Member Functions inherited from duckdb::BaseExpression
static bool Equals (const BaseExpression &left, const BaseExpression &right)

Public Attributes

unique_ptr< Expression > child
 The child type.
bool try_cast
 Whether to use try_cast or not. try_cast converts cast failures into NULLs instead of throwing an error.
BoundCastInfo bound_cast
 The bound cast info.
Public Attributes inherited from duckdb::Expression
LogicalType return_type
 The return type of the expression.
unique_ptr< BaseStatistics > verification_stats
 Expression statistics (if any) - ONLY USED FOR VERIFICATION.
Public Attributes inherited from duckdb::BaseExpression
ExpressionType type
 Type of the expression.
ExpressionClass expression_class
 The expression class of the node.
string alias
 The alias of the expression,.
optional_idx query_location
 The location in the query (if any).

Static Public Attributes

static constexpr const ExpressionClass TYPE = ExpressionClass::BOUND_CAST

Private Member Functions

 BoundCastExpression (ClientContext &context, unique_ptr< Expression > child, LogicalType target_type)

Additional Inherited Members

Protected Member Functions inherited from duckdb::Expression
void CopyProperties (const Expression &other)

Constructor & Destructor Documentation

◆ BoundCastExpression() [1/2]

duckdb::BoundCastExpression::BoundCastExpression ( unique_ptr< Expression > child,
LogicalType target_type,
BoundCastInfo bound_cast,
bool try_cast = false )
375786 : Expression(ExpressionType::OPERATOR_CAST, ExpressionClass::BOUND_CAST, std::move(target_type_p)),
375787 child(std::move(child_p)), try_cast(try_cast_p), bound_cast(std::move(bound_cast_p)) {
375788}
bool try_cast
Whether to use try_cast or not. try_cast converts cast failures into NULLs instead of throwing an err...
Definition duckdb.cpp:80898
BoundCastInfo bound_cast
The bound cast info.
Definition duckdb.cpp:80900
unique_ptr< Expression > child
The child type.
Definition duckdb.cpp:80896

◆ BoundCastExpression() [2/2]

duckdb::BoundCastExpression::BoundCastExpression ( ClientContext & context,
unique_ptr< Expression > child,
LogicalType target_type )
private
375792 : Expression(ExpressionType::OPERATOR_CAST, ExpressionClass::BOUND_CAST, std::move(target_type_p)),
375793 child(std::move(child_p)), try_cast(false),
375794 bound_cast(BindCastFunction(context, child->return_type, return_type)) {
375795}
LogicalType return_type
The return type of the expression.
Definition duckdb.hpp:17743

Member Function Documentation

◆ source_type()

LogicalType duckdb::BoundCastExpression::source_type ( )
inline
80903 { // NOLINT: allow casing for legacy reasons
80904 D_ASSERT(child->return_type.IsValid());
80905 return child->return_type;
80906 }

◆ AddDefaultCastToType()

unique_ptr< Expression > duckdb::BoundCastExpression::AddDefaultCastToType ( unique_ptr< Expression > expr,
const LogicalType & target_type,
bool try_cast = false )
static

Cast an expression to the specified SQL type, using only the built-in SQL casts.

375862 {
375863 CastFunctionSet default_set;
375864 GetCastFunctionInput get_input;
375865 get_input.query_location = expr->GetQueryLocation();
375866 return AddCastToTypeInternal(std::move(expr), target_type, default_set, get_input, try_cast);
375867}

◆ AddCastToType()

unique_ptr< Expression > duckdb::BoundCastExpression::AddCastToType ( ClientContext & context,
unique_ptr< Expression > expr,
const LogicalType & target_type,
bool try_cast = false )
static

Cast an expression to the specified SQL type if required.

375870 {
375871 auto &cast_functions = DBConfig::GetConfig(context).GetCastFunctions();
375872 GetCastFunctionInput get_input(context);
375873 get_input.query_location = expr->GetQueryLocation();
375874 return AddCastToTypeInternal(std::move(expr), target_type, cast_functions, get_input, try_cast);
375875}
Here is the caller graph for this function:

◆ AddArrayCastToList()

unique_ptr< Expression > duckdb::BoundCastExpression::AddArrayCastToList ( ClientContext & context,
unique_ptr< Expression > expr )
static

If the expression returns an array, cast it to return a list with the same child type. Otherwise do nothing.

375877 {
375878 if (expr->return_type.id() != LogicalTypeId::ARRAY) {
375879 return expr;
375880 }
375881 auto &child_type = ArrayType::GetChildType(expr->return_type);
375882 return BoundCastExpression::AddCastToType(context, std::move(expr), LogicalType::LIST(child_type));
375883}
static DUCKDB_API unique_ptr< Expression > AddCastToType(ClientContext &context, unique_ptr< Expression > expr, const LogicalType &target_type, bool try_cast=false)
Cast an expression to the specified SQL type if required.
Definition duckdb.cpp:375869
Here is the call graph for this function:

◆ CastIsInvertible()

bool duckdb::BoundCastExpression::CastIsInvertible ( const LogicalType & source_type,
const LogicalType & target_type )
static

Returns true if a cast is invertible (i.e. CAST(s -> t -> s) = s for all values of s). This is not true for e.g. boolean casts, because that can be e.g. -1 -> TRUE -> 1. This is necessary to prevent some optimizer bugs.

375885 {
375886 D_ASSERT(source_type.IsValid() && target_type.IsValid());
375887 if (source_type.id() == LogicalTypeId::BOOLEAN || target_type.id() == LogicalTypeId::BOOLEAN) {
375888 return false;
375889 }
375890 if (source_type.id() == LogicalTypeId::FLOAT || target_type.id() == LogicalTypeId::FLOAT) {
375891 return false;
375892 }
375893 if (source_type.id() == LogicalTypeId::DOUBLE || target_type.id() == LogicalTypeId::DOUBLE) {
375894 return false;
375895 }
375896 if (source_type.id() == LogicalTypeId::VARIANT || target_type.id() == LogicalTypeId::VARIANT) {
375897 return false;
375898 }
375899 if (source_type.id() == LogicalTypeId::DECIMAL || target_type.id() == LogicalTypeId::DECIMAL) {
375900 uint8_t source_width, target_width;
375901 uint8_t source_scale, target_scale;
375902 // cast to or from decimal
375903 // cast is only invertible if the cast is strictly widening
375904 if (!source_type.GetDecimalProperties(source_width, source_scale)) {
375905 return false;
375906 }
375907 if (!target_type.GetDecimalProperties(target_width, target_scale)) {
375908 return false;
375909 }
375910 if (target_scale < source_scale) {
375911 return false;
375912 }
375913 return true;
375914 }
375915 switch (source_type.id()) {
375916 case LogicalTypeId::TIMESTAMP:
375917 case LogicalTypeId::TIMESTAMP_TZ:
375918 case LogicalTypeId::TIMESTAMP_SEC:
375919 case LogicalTypeId::TIMESTAMP_MS:
375921 switch (target_type.id()) {
375922 // see types.hpp to see timestamp ranking
375923 case LogicalTypeId::TIMESTAMP:
375924 return source_type.id() <= LogicalTypeId::TIMESTAMP;
375925 case LogicalTypeId::TIMESTAMP_SEC:
375926 return source_type.id() <= LogicalTypeId::TIMESTAMP_SEC;
375927 case LogicalTypeId::TIMESTAMP_MS:
375928 return source_type.id() <= LogicalTypeId::TIMESTAMP_MS;
375930 return source_type.id() <= LogicalTypeId::TIMESTAMP_NS;
375931 case LogicalTypeId::DATE:
375932 case LogicalTypeId::TIME:
375933 case LogicalTypeId::TIME_TZ:
375934 return false;
375935 case LogicalTypeId::TIMESTAMP_TZ:
375936 return source_type.id() == LogicalTypeId::TIMESTAMP_TZ;
375937 default:
375938 break;
375939 }
375940 break;
375941 case LogicalTypeId::VARCHAR:
375942 case LogicalTypeId::BIT:
375943 case LogicalTypeId::TIME_TZ:
375944 return false;
375945 default:
375946 break;
375947 }
375948 if (target_type.id() == LogicalTypeId::VARCHAR) {
375949 switch (source_type.id()) {
375950 case LogicalTypeId::DATE:
375951 case LogicalTypeId::TIME:
375952 case LogicalTypeId::TIME_NS:
375953 case LogicalTypeId::TIMESTAMP:
375955 case LogicalTypeId::TIMESTAMP_MS:
375956 case LogicalTypeId::TIMESTAMP_SEC:
375957 case LogicalTypeId::TIME_TZ:
375958 case LogicalTypeId::TIMESTAMP_TZ:
375959 return true;
375960 default:
375961 return false;
375962 }
375963 }
375964 if (source_type.IsSigned() && target_type.IsUnsigned()) {
375965 return false;
375966 }
375967 return true;
375968}
::uint8_t uint8_t
@ TIMESTAMP_NS
us
Definition duckdb.hpp:2886
DUCKDB_API bool GetDecimalProperties(uint8_t &width, uint8_t &scale) const
Gets the decimal properties of a numeric type. Fails if the type is not numeric.
Definition duckdb.cpp:139765
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToString()

string duckdb::BoundCastExpression::ToString ( ) const
overridevirtual

Convert the Expression to a String.

Implements duckdb::BaseExpression.

375970 {
375971 return (try_cast ? "TRY_CAST(" : "CAST(") + child->GetName() + " AS " + return_type.ToString() + ")";
375972}

◆ Equals()

bool duckdb::BoundCastExpression::Equals ( const BaseExpression & other) const
overridevirtual

Returns true if this expression is equal to another expression.

Reimplemented from duckdb::BaseExpression.

375974 {
375975 if (!Expression::Equals(other_p)) {
375976 return false;
375977 }
375978 auto &other = other_p.Cast<BoundCastExpression>();
375979 if (!Expression::Equals(*child, *other.child)) {
375980 return false;
375981 }
375982 if (try_cast != other.try_cast) {
375983 return false;
375984 }
375985 return true;
375986}
bool Equals(const BaseExpression &other) const override
Returns true if this expression is equal to another expression.
Definition duckdb.hpp:17762
Here is the call graph for this function:

◆ Copy()

unique_ptr< Expression > duckdb::BoundCastExpression::Copy ( ) const
overridevirtual

Create a copy of this expression.

Implements duckdb::Expression.

375988 {
375989 auto copy = make_uniq<BoundCastExpression>(child->Copy(), return_type, bound_cast.Copy(), try_cast);
375990 copy->CopyProperties(*this);
375991 return std::move(copy);
375992}

◆ CanThrow()

bool duckdb::BoundCastExpression::CanThrow ( ) const
overridevirtual

Reimplemented from duckdb::Expression.

375994 {
375995 const auto child_type = child->return_type;
375996 if (return_type.id() != child_type.id() &&
375997 LogicalType::ForceMaxLogicalType(return_type, child_type) == child_type.id()) {
375998 return true;
375999 }
376000 // Casting VARCHAR to JSON involves parsing and validation that can throw on malformed input
376001 if (return_type.IsJSONType() && !child_type.IsJSONType()) {
376002 return true;
376003 }
376004 bool changes_type = false;
376005 ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) { changes_type |= child.CanThrow(); });
376006 return changes_type;
376007}
static DUCKDB_API LogicalType ForceMaxLogicalType(const LogicalType &left, const LogicalType &right)
Forcibly returns a maximum logical type - similar to MaxLogicalType but never throws....
Definition duckdb.cpp:140319

◆ Serialize()

void duckdb::BoundCastExpression::Serialize ( Serializer & serializer) const
overridevirtual

Reimplemented from duckdb::Expression.

416034 {
416035 Expression::Serialize(serializer);
416036 serializer.WritePropertyWithDefault<unique_ptr<Expression>>(200, "child", child);
416037 serializer.WriteProperty<LogicalType>(201, "return_type", return_type);
416038 serializer.WritePropertyWithDefault<bool>(202, "try_cast", try_cast);
416039}

◆ Deserialize()

unique_ptr< Expression > duckdb::BoundCastExpression::Deserialize ( Deserializer & deserializer)
static
416041 {
416042 auto child = deserializer.ReadPropertyWithDefault<unique_ptr<Expression>>(200, "child");
416043 auto return_type = deserializer.ReadProperty<LogicalType>(201, "return_type");
416044 auto result = duckdb::unique_ptr<BoundCastExpression>(new BoundCastExpression(deserializer.Get<ClientContext &>(), std::move(child), std::move(return_type)));
416045 deserializer.ReadPropertyWithDefault<bool>(202, "try_cast", result->try_cast);
416046 return std::move(result);
416047}

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