1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/function/scalar/nested_functions.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/function/function_set.hpp"
12#include "duckdb/function/scalar_function.hpp"
13#include "duckdb/common/map.hpp"
14#include "duckdb/common/unordered_map.hpp"
15#include "duckdb/common/field_writer.hpp"
16#include "duckdb/function/built_in_functions.hpp"
17#include "duckdb/function/scalar/list/contains_or_position.hpp"
18
19namespace duckdb {
20
21struct ListArgFunctor {
22 static Vector &GetList(Vector &list) {
23 return list;
24 }
25 static idx_t GetListSize(Vector &list) {
26 return ListVector::GetListSize(vector: list);
27 }
28 static Vector &GetEntry(Vector &list) {
29 return ListVector::GetEntry(vector&: list);
30 }
31};
32
33struct ContainsFunctor {
34 static inline bool Initialize() {
35 return false;
36 }
37 static inline bool UpdateResultEntries(idx_t child_idx) {
38 return true;
39 }
40};
41
42struct PositionFunctor {
43 static inline int32_t Initialize() {
44 return 0;
45 }
46 static inline int32_t UpdateResultEntries(idx_t child_idx) {
47 return child_idx + 1;
48 }
49};
50
51struct VariableReturnBindData : public FunctionData {
52 LogicalType stype;
53
54 explicit VariableReturnBindData(LogicalType stype_p) : stype(std::move(stype_p)) {
55 }
56
57 unique_ptr<FunctionData> Copy() const override {
58 return make_uniq<VariableReturnBindData>(args: stype);
59 }
60 bool Equals(const FunctionData &other_p) const override {
61 auto &other = (const VariableReturnBindData &)other_p;
62 return stype == other.stype;
63 }
64
65 static void Serialize(FieldWriter &writer, const FunctionData *bind_data_p, const ScalarFunction &function) {
66 D_ASSERT(bind_data_p);
67 auto &info = bind_data_p->Cast<VariableReturnBindData>();
68 writer.WriteSerializable(element: info.stype);
69 }
70
71 static unique_ptr<FunctionData> Deserialize(PlanDeserializationState &context, FieldReader &reader,
72 ScalarFunction &bound_function) {
73 auto stype = reader.ReadRequiredSerializable<LogicalType, LogicalType>();
74 return make_uniq<VariableReturnBindData>(args: std::move(stype));
75 }
76};
77
78template <class T, class MAP_TYPE = map<T, idx_t>>
79struct HistogramAggState {
80 MAP_TYPE *hist;
81};
82
83struct ListExtractFun {
84 static void RegisterFunction(BuiltinFunctions &set);
85};
86
87struct ListConcatFun {
88 static ScalarFunction GetFunction();
89 static void RegisterFunction(BuiltinFunctions &set);
90};
91
92struct ListContainsFun {
93 static ScalarFunction GetFunction();
94 static void RegisterFunction(BuiltinFunctions &set);
95};
96
97struct ListPositionFun {
98 static ScalarFunction GetFunction();
99 static void RegisterFunction(BuiltinFunctions &set);
100};
101
102struct StructExtractFun {
103 static ScalarFunction GetFunction();
104 static void RegisterFunction(BuiltinFunctions &set);
105};
106
107} // namespace duckdb
108