1#include <Functions/IFunctionImpl.h>
2#include <Storages/IStorage_fwd.h>
3#include <Storages/TableStructureLockHolder.h>
4
5namespace DB
6{
7
8class Context;
9class Join;
10using HashJoinPtr = std::shared_ptr<Join>;
11
12class ExecutableFunctionJoinGet final : public IExecutableFunctionImpl
13{
14public:
15 ExecutableFunctionJoinGet(HashJoinPtr join_, String attr_name_)
16 : join(std::move(join_)), attr_name(std::move(attr_name_)) {}
17
18 static constexpr auto name = "joinGet";
19
20 void execute(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override;
21
22 String getName() const override { return name; }
23
24private:
25 HashJoinPtr join;
26 const String attr_name;
27};
28
29class FunctionJoinGet final : public IFunctionBaseImpl
30{
31public:
32 static constexpr auto name = "joinGet";
33
34 FunctionJoinGet(TableStructureReadLockHolder table_lock_, StoragePtr storage_join_,
35 HashJoinPtr join_, String attr_name_,
36 DataTypes argument_types_, DataTypePtr return_type_)
37 : table_lock(std::move(table_lock_))
38 , storage_join(std::move(storage_join_))
39 , join(std::move(join_))
40 , attr_name(std::move(attr_name_))
41 , argument_types(std::move(argument_types_))
42 , return_type(std::move(return_type_))
43 {
44 }
45
46 String getName() const override { return name; }
47
48 const DataTypes & getArgumentTypes() const override { return argument_types; }
49 const DataTypePtr & getReturnType() const override { return return_type; }
50
51 ExecutableFunctionImplPtr prepare(const Block & sample_block, const ColumnNumbers & arguments, size_t result) const override;
52
53private:
54 TableStructureReadLockHolder table_lock;
55 StoragePtr storage_join;
56 HashJoinPtr join;
57 const String attr_name;
58 DataTypes argument_types;
59 DataTypePtr return_type;
60};
61
62class JoinGetOverloadResolver final : public IFunctionOverloadResolverImpl
63{
64public:
65 static constexpr auto name = "joinGet";
66 static FunctionOverloadResolverImplPtr create(const Context & context) { return std::make_unique<JoinGetOverloadResolver>(context); }
67
68 explicit JoinGetOverloadResolver(const Context & context_) : context(context_) {}
69
70 String getName() const override { return name; }
71
72 FunctionBaseImplPtr build(const ColumnsWithTypeAndName & arguments, const DataTypePtr &) const override;
73 DataTypePtr getReturnType(const ColumnsWithTypeAndName & arguments) const override;
74
75 bool isVariadic() const override { return true; }
76 size_t getNumberOfArguments() const override { return 0; }
77
78private:
79 const Context & context;
80};
81
82}
83