ClickHouse/src/Functions/FunctionJoinGet.h

95 lines
3.3 KiB
C++
Raw Normal View History

#include <Functions/IFunctionImpl.h>
#include <Storages/IStorage_fwd.h>
2020-06-22 09:49:21 +00:00
#include <Storages/TableLockHolder.h>
namespace DB
{
2019-09-09 19:43:37 +00:00
class Context;
class HashJoin;
using HashJoinPtr = std::shared_ptr<HashJoin>;
2020-04-07 14:52:32 +00:00
template <bool or_null>
2019-12-09 14:41:55 +00:00
class ExecutableFunctionJoinGet final : public IExecutableFunctionImpl
{
public:
ExecutableFunctionJoinGet(HashJoinPtr join_, const Block & result_block_)
: join(std::move(join_)), result_block(result_block_) {}
2019-12-09 14:41:55 +00:00
2020-04-07 14:52:32 +00:00
static constexpr auto name = or_null ? "joinGetOrNull" : "joinGet";
bool useDefaultImplementationForNulls() const override { return false; }
bool useDefaultImplementationForLowCardinalityColumns() const override { return true; }
bool useDefaultImplementationForConstants() const override { return true; }
2019-12-09 14:41:55 +00:00
void execute(Block & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override;
String getName() const override { return name; }
private:
HashJoinPtr join;
Block result_block;
2019-12-09 14:41:55 +00:00
};
2020-04-07 14:52:32 +00:00
template <bool or_null>
2019-12-09 14:41:55 +00:00
class FunctionJoinGet final : public IFunctionBaseImpl
{
public:
2020-04-07 14:52:32 +00:00
static constexpr auto name = or_null ? "joinGetOrNull" : "joinGet";
2019-12-09 14:41:55 +00:00
2020-06-18 16:10:47 +00:00
FunctionJoinGet(TableLockHolder table_lock_, StoragePtr storage_join_,
2019-12-09 14:41:55 +00:00
HashJoinPtr join_, String attr_name_,
DataTypes argument_types_, DataTypePtr return_type_)
2019-08-03 11:02:40 +00:00
: table_lock(std::move(table_lock_))
, storage_join(std::move(storage_join_))
, join(std::move(join_))
2019-12-09 14:41:55 +00:00
, attr_name(std::move(attr_name_))
, argument_types(std::move(argument_types_))
2019-08-03 11:02:40 +00:00
, return_type(std::move(return_type_))
2019-01-25 14:50:31 +00:00
{
}
String getName() const override { return name; }
2019-12-09 14:41:55 +00:00
const DataTypes & getArgumentTypes() const override { return argument_types; }
const DataTypePtr & getReturnType() const override { return return_type; }
2019-12-09 14:41:55 +00:00
ExecutableFunctionImplPtr prepare(const Block & sample_block, const ColumnNumbers & arguments, size_t result) const override;
private:
2020-06-18 16:10:47 +00:00
TableLockHolder table_lock;
2019-01-25 14:50:31 +00:00
StoragePtr storage_join;
2019-09-09 19:43:37 +00:00
HashJoinPtr join;
const String attr_name;
2019-12-09 14:41:55 +00:00
DataTypes argument_types;
2019-01-25 14:50:31 +00:00
DataTypePtr return_type;
};
2020-04-07 14:52:32 +00:00
template <bool or_null>
class JoinGetOverloadResolver final : public IFunctionOverloadResolverImpl
{
public:
2020-04-07 14:52:32 +00:00
static constexpr auto name = or_null ? "joinGetOrNull" : "joinGet";
static FunctionOverloadResolverImplPtr create(const Context & context) { return std::make_unique<JoinGetOverloadResolver>(context); }
explicit JoinGetOverloadResolver(const Context & context_) : context(context_) {}
String getName() const override { return name; }
2019-12-09 14:41:55 +00:00
FunctionBaseImplPtr build(const ColumnsWithTypeAndName & arguments, const DataTypePtr &) const override;
DataTypePtr getReturnType(const ColumnsWithTypeAndName &) const override { return {}; }
bool useDefaultImplementationForNulls() const override { return false; }
bool useDefaultImplementationForLowCardinalityColumns() const override { return true; }
bool isVariadic() const override { return true; }
size_t getNumberOfArguments() const override { return 0; }
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {2}; }
void checkNumberOfArgumentsIfVariadic(size_t number_of_arguments) const override;
private:
const Context & context;
};
}