1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/function/function_set.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/function/aggregate_function.hpp"
12#include "duckdb/function/scalar_function.hpp"
13#include "duckdb/function/table_function.hpp"
14#include "duckdb/function/pragma_function.hpp"
15
16namespace duckdb {
17
18template <class T>
19class FunctionSet {
20public:
21 explicit FunctionSet(string name) : name(name) {
22 }
23
24 //! The name of the function set
25 string name;
26 //! The set of functions.
27 vector<T> functions;
28
29public:
30 void AddFunction(T function) {
31 functions.push_back(std::move(function));
32 }
33 idx_t Size() {
34 return functions.size();
35 }
36 T GetFunctionByOffset(idx_t offset) {
37 D_ASSERT(offset < functions.size());
38 return functions[offset];
39 }
40 T &GetFunctionReferenceByOffset(idx_t offset) {
41 D_ASSERT(offset < functions.size());
42 return functions[offset];
43 }
44 bool MergeFunctionSet(FunctionSet<T> new_functions) {
45 D_ASSERT(!new_functions.functions.empty());
46 bool need_rewrite_entry = false;
47 for (auto &new_func : new_functions.functions) {
48 bool can_add = true;
49 for (auto &func : functions) {
50 if (new_func.Equal(func)) {
51 can_add = false;
52 break;
53 }
54 }
55 if (can_add) {
56 functions.push_back(new_func);
57 need_rewrite_entry = true;
58 }
59 }
60 return need_rewrite_entry;
61 }
62};
63
64class ScalarFunctionSet : public FunctionSet<ScalarFunction> {
65public:
66 DUCKDB_API explicit ScalarFunctionSet();
67 DUCKDB_API explicit ScalarFunctionSet(string name);
68 DUCKDB_API explicit ScalarFunctionSet(ScalarFunction fun);
69
70 DUCKDB_API ScalarFunction GetFunctionByArguments(ClientContext &context, const vector<LogicalType> &arguments);
71};
72
73class AggregateFunctionSet : public FunctionSet<AggregateFunction> {
74public:
75 DUCKDB_API explicit AggregateFunctionSet();
76 DUCKDB_API explicit AggregateFunctionSet(string name);
77 DUCKDB_API explicit AggregateFunctionSet(AggregateFunction fun);
78
79 DUCKDB_API AggregateFunction GetFunctionByArguments(ClientContext &context, const vector<LogicalType> &arguments);
80};
81
82class TableFunctionSet : public FunctionSet<TableFunction> {
83public:
84 DUCKDB_API explicit TableFunctionSet(string name);
85 DUCKDB_API explicit TableFunctionSet(TableFunction fun);
86
87 TableFunction GetFunctionByArguments(ClientContext &context, const vector<LogicalType> &arguments);
88};
89
90class PragmaFunctionSet : public FunctionSet<PragmaFunction> {
91public:
92 DUCKDB_API explicit PragmaFunctionSet(string name);
93 DUCKDB_API explicit PragmaFunctionSet(PragmaFunction fun);
94};
95
96} // namespace duckdb
97