1#include "duckdb/common/limits.hpp"
2#include "duckdb/common/vector_operations/vector_operations.hpp"
3#include "duckdb/function/cast/cast_function_set.hpp"
4#include "duckdb/main/config.hpp"
5#include "duckdb/function/scalar_function.hpp"
6
7namespace duckdb {
8
9bool VectorOperations::TryCast(CastFunctionSet &set, GetCastFunctionInput &input, Vector &source, Vector &result,
10 idx_t count, string *error_message, bool strict) {
11 auto cast_function = set.GetCastFunction(source: source.GetType(), target: result.GetType(), input);
12 unique_ptr<FunctionLocalState> local_state;
13 if (cast_function.init_local_state) {
14 CastLocalStateParameters lparameters(input.context, cast_function.cast_data);
15 local_state = cast_function.init_local_state(lparameters);
16 }
17 CastParameters parameters(cast_function.cast_data.get(), strict, error_message, local_state.get());
18 return cast_function.function(source, result, count, parameters);
19}
20
21bool VectorOperations::DefaultTryCast(Vector &source, Vector &result, idx_t count, string *error_message, bool strict) {
22 CastFunctionSet set;
23 GetCastFunctionInput input;
24 return VectorOperations::TryCast(set, input, source, result, count, error_message, strict);
25}
26
27void VectorOperations::DefaultCast(Vector &source, Vector &result, idx_t count, bool strict) {
28 VectorOperations::DefaultTryCast(source, result, count, error_message: nullptr, strict);
29}
30
31bool VectorOperations::TryCast(ClientContext &context, Vector &source, Vector &result, idx_t count,
32 string *error_message, bool strict) {
33 auto &config = DBConfig::GetConfig(context);
34 auto &set = config.GetCastFunctions();
35 GetCastFunctionInput get_input(context);
36 return VectorOperations::TryCast(set, input&: get_input, source, result, count, error_message, strict);
37}
38
39void VectorOperations::Cast(ClientContext &context, Vector &source, Vector &result, idx_t count, bool strict) {
40 VectorOperations::TryCast(context, source, result, count, error_message: nullptr, strict);
41}
42
43} // namespace duckdb
44