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::CastFunctionSet Class Reference
Collaboration diagram for duckdb::CastFunctionSet:

Public Member Functions

 CastFunctionSet (DBConfig &config)
DUCKDB_API BoundCastInfo GetCastFunction (const LogicalType &source, const LogicalType &target, GetCastFunctionInput &input)
 Returns a cast function (from source -> target) Note that this always returns a function - since a cast is ALWAYS possible if the value is NULL.
DUCKDB_API int64_t ImplicitCastCost (optional_ptr< ClientContext > context, const LogicalType &source, const LogicalType &target)
 Returns the implicit cast cost of casting from source -> target -1 means an implicit cast is not possible.
DUCKDB_API void RegisterCastFunction (const LogicalType &source, const LogicalType &target, BoundCastInfo function, int64_t implicit_cast_cost=-1)
 Register a new cast function from source to target.
DUCKDB_API void RegisterCastFunction (const LogicalType &source, const LogicalType &target, bind_cast_function_t bind, int64_t implicit_cast_cost=-1)

Static Public Member Functions

static DUCKDB_API CastFunctionSet & Get (ClientContext &context)
static DUCKDB_API CastFunctionSet & Get (DatabaseInstance &db)
static DUCKDB_API int64_t ImplicitCastCost (ClientContext &context, const LogicalType &source, const LogicalType &target)
static DUCKDB_API int64_t ImplicitCastCost (DatabaseInstance &db, const LogicalType &source, const LogicalType &target)

Private Member Functions

void RegisterCastFunction (const LogicalType &source, const LogicalType &target, MapCastNode node)

Private Attributes

optional_ptr< DBConfig > config
vector< BindCastFunction > bind_functions
optional_ptr< MapCastInfo > map_info
 If any custom cast functions have been defined using RegisterCastFunction, this holds the map.

Constructor & Destructor Documentation

◆ CastFunctionSet() [1/2]

duckdb::CastFunctionSet::CastFunctionSet ( )
213107 : map_info(nullptr) {
213108 bind_functions.emplace_back(DefaultCasts::GetDefaultCastFunction);
213109}
optional_ptr< MapCastInfo > map_info
If any custom cast functions have been defined using RegisterCastFunction, this holds the map.
Definition duckdb.hpp:43935

◆ CastFunctionSet() [2/2]

duckdb::CastFunctionSet::CastFunctionSet ( DBConfig & config)
explicit
213111 : CastFunctionSet() {
213112 this->config = &config_p;
213113}

Member Function Documentation

◆ Get() [1/2]

CastFunctionSet & duckdb::CastFunctionSet::Get ( ClientContext & context)
static
213115 {
213116 return DBConfig::GetConfig(context).GetCastFunctions();
213117}

◆ Get() [2/2]

CastFunctionSet & duckdb::CastFunctionSet::Get ( DatabaseInstance & db)
static
213123 {
213124 return DBConfig::GetConfig(db).GetCastFunctions();
213125}

◆ GetCastFunction()

BoundCastInfo duckdb::CastFunctionSet::GetCastFunction ( const LogicalType & source,
const LogicalType & target,
GetCastFunctionInput & input )

Returns a cast function (from source -> target) Note that this always returns a function - since a cast is ALWAYS possible if the value is NULL.

213132 {
213133 if (source == target) {
213134 return DefaultCasts::NopCast;
213135 }
213136 // the first function is the default
213137 // we iterate the set of bind functions backwards
213138 for (idx_t i = bind_functions.size(); i > 0; i--) {
213139 auto &bind_function = bind_functions[i - 1];
213140 BindCastInput input(*this, bind_function.info.get(), get_input.context);
213141 input.query_location = get_input.query_location;
213142 auto result = bind_function.function(input, source, target);
213143 if (result.function) {
213144 // found a cast function! return it
213145 return result;
213146 }
213147 }
213148 // no cast found: return the default null cast
213149 return DefaultCasts::TryVectorNullCast;
213150}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the caller graph for this function:

◆ ImplicitCastCost() [1/3]

int64_t duckdb::CastFunctionSet::ImplicitCastCost ( optional_ptr< ClientContext > context,
const LogicalType & source,
const LogicalType & target )

Returns the implicit cast cost of casting from source -> target -1 means an implicit cast is not possible.

213250 {
213251 // check if a cast has been registered
213252 if (map_info) {
213253 auto entry = map_info->GetEntry(source, target);
213254 if (entry) {
213255 return entry->implicit_cast_cost;
213256 }
213257 }
213258 // if not, fallback to the default implicit cast rules
213259 auto score = CastRules::ImplicitCast(source, target);
213260 if (score < 0 && source.id() != LogicalTypeId::BLOB && target.id() == LogicalTypeId::VARCHAR) {
213261 bool old_implicit_casting = false;
213262 if (context) {
213263 old_implicit_casting = Settings::Get<OldImplicitCastingSetting>(*context);
213264 } else if (config) {
213265 old_implicit_casting = Settings::Get<OldImplicitCastingSetting>(*config);
213266 }
213267 if (old_implicit_casting) {
213268 // very high cost to avoid choosing this cast if any other option is available
213269 // (it should be more costly than casting to TEMPLATE if that is available)
213270 score = 10000000000;
213271 }
213272 }
213273 return score;
213274}
static int64_t ImplicitCast(const LogicalType &from, const LogicalType &to)
Returns the cost of performing an implicit cost from "from" to "to", or -1 if an implicit cast is not...
Definition duckdb.cpp:219858
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImplicitCastCost() [2/3]

int64_t duckdb::CastFunctionSet::ImplicitCastCost ( ClientContext & context,
const LogicalType & source,
const LogicalType & target )
static
213277 {
213278 return CastFunctionSet::Get(context).ImplicitCastCost(&context, source, target);
213279}

◆ ImplicitCastCost() [3/3]

int64_t duckdb::CastFunctionSet::ImplicitCastCost ( DatabaseInstance & db,
const LogicalType & source,
const LogicalType & target )
static
213281 {
213282 return CastFunctionSet::Get(db).ImplicitCastCost(nullptr, source, target);
213283}

◆ RegisterCastFunction() [1/3]

void duckdb::CastFunctionSet::RegisterCastFunction ( const LogicalType & source,
const LogicalType & target,
BoundCastInfo function,
int64_t implicit_cast_cost = -1 )

Register a new cast function from source to target.

213299 {
213300 RegisterCastFunction(source, target, MapCastNode(std::move(function), implicit_cast_cost));
213301}
DUCKDB_API void RegisterCastFunction(const LogicalType &source, const LogicalType &target, BoundCastInfo function, int64_t implicit_cast_cost=-1)
Register a new cast function from source to target.
Definition duckdb.cpp:213298
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterCastFunction() [2/3]

void duckdb::CastFunctionSet::RegisterCastFunction ( const LogicalType & source,
const LogicalType & target,
bind_cast_function_t bind,
int64_t implicit_cast_cost = -1 )
213304 {
213305 RegisterCastFunction(source, target, MapCastNode(bind_function, implicit_cast_cost));
213306}

◆ RegisterCastFunction() [3/3]

void duckdb::CastFunctionSet::RegisterCastFunction ( const LogicalType & source,
const LogicalType & target,
MapCastNode node )
private
213308 {
213309 if (!map_info) {
213310 // create the cast map and the cast map function
213311 auto info = make_uniq<MapCastInfo>();
213312 map_info = info.get();
213313 bind_functions.emplace_back(MapCastFunction, std::move(info));
213314 }
213315 map_info->AddEntry(source, target, std::move(node));
213316}

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