//===----------------------------------------------------------------------===// // DuckDB // // duckdb/function/function_binder.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/function/function.hpp" #include "duckdb/function/cast/cast_function_set.hpp" #include "duckdb/function/scalar_function.hpp" #include "duckdb/function/aggregate_function.hpp" #include "duckdb/function/function_set.hpp" namespace duckdb { //! The FunctionBinder class is responsible for binding functions class FunctionBinder { public: DUCKDB_API explicit FunctionBinder(ClientContext &context); ClientContext &context; public: //! Bind a scalar function from the set of functions and input arguments. Returns the index of the chosen function, //! returns DConstants::INVALID_INDEX and sets error if none could be found DUCKDB_API idx_t BindFunction(const string &name, ScalarFunctionSet &functions, const vector &arguments, string &error); DUCKDB_API idx_t BindFunction(const string &name, ScalarFunctionSet &functions, vector> &arguments, string &error); //! Bind an aggregate function from the set of functions and input arguments. Returns the index of the chosen //! function, returns DConstants::INVALID_INDEX and sets error if none could be found DUCKDB_API idx_t BindFunction(const string &name, AggregateFunctionSet &functions, const vector &arguments, string &error); DUCKDB_API idx_t BindFunction(const string &name, AggregateFunctionSet &functions, vector> &arguments, string &error); //! Bind a table function from the set of functions and input arguments. Returns the index of the chosen //! function, returns DConstants::INVALID_INDEX and sets error if none could be found DUCKDB_API idx_t BindFunction(const string &name, TableFunctionSet &functions, const vector &arguments, string &error); DUCKDB_API idx_t BindFunction(const string &name, TableFunctionSet &functions, vector> &arguments, string &error); //! Bind a pragma function from the set of functions and input arguments DUCKDB_API idx_t BindFunction(const string &name, PragmaFunctionSet &functions, PragmaInfo &info, string &error); DUCKDB_API unique_ptr BindScalarFunction(const string &schema, const string &name, vector> children, string &error, bool is_operator = false, Binder *binder = nullptr); DUCKDB_API unique_ptr BindScalarFunction(ScalarFunctionCatalogEntry &function, vector> children, string &error, bool is_operator = false, Binder *binder = nullptr); DUCKDB_API unique_ptr BindScalarFunction(ScalarFunction bound_function, vector> children, bool is_operator = false); DUCKDB_API unique_ptr BindAggregateFunction(AggregateFunction bound_function, vector> children, unique_ptr filter = nullptr, AggregateType aggr_type = AggregateType::NON_DISTINCT); DUCKDB_API static void BindSortedAggregate(ClientContext &context, BoundAggregateExpression &expr, const vector> &groups); private: //! Cast a set of expressions to the arguments of this function void CastToFunctionArguments(SimpleFunction &function, vector> &children); int64_t BindVarArgsFunctionCost(const SimpleFunction &func, const vector &arguments); int64_t BindFunctionCost(const SimpleFunction &func, const vector &arguments); template vector BindFunctionsFromArguments(const string &name, FunctionSet &functions, const vector &arguments, string &error); template idx_t MultipleCandidateException(const string &name, FunctionSet &functions, vector &candidate_functions, const vector &arguments, string &error); template idx_t BindFunctionFromArguments(const string &name, FunctionSet &functions, const vector &arguments, string &error); vector GetLogicalTypesFromExpressions(vector> &arguments); }; } // namespace duckdb