ClickHouse/src/Functions/FunctionJoinGet.h

95 lines
3.2 KiB
C++
Raw Normal View History

2020-10-10 18:37:02 +00:00
#pragma once
#include <Functions/IFunctionImpl.h>
#include <Storages/IStorage_fwd.h>
2020-06-22 09:49:21 +00:00
#include <Storages/TableLockHolder.h>
#include <Core/Block.h>
namespace DB
{
2019-09-09 19:43:37 +00:00
class Context;
class HashJoin;
class HashJoinHolder;
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(std::shared_ptr<HashJoinHolder> join_, const DB::Block & result_columns_)
2020-10-14 14:04:50 +00:00
: join(std::move(join_)), result_columns(result_columns_) {}
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; }
ColumnPtr execute(const ColumnsWithTypeAndName & arguments, const DataTypePtr &, size_t input_rows_count) const override;
2019-12-09 14:41:55 +00:00
String getName() const override { return name; }
private:
std::shared_ptr<HashJoinHolder> join;
2020-10-14 14:04:50 +00:00
DB::Block result_columns;
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
FunctionJoinGet(TableLockHolder table_lock_,
std::shared_ptr<HashJoinHolder> join_, String attr_name_,
2019-12-09 14:41:55 +00:00
DataTypes argument_types_, DataTypePtr return_type_)
2019-08-03 11:02:40 +00:00
: table_lock(std::move(table_lock_))
, join(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; }
2020-10-17 21:41:50 +00:00
const DataTypePtr & getResultType() const override { return return_type; }
2020-10-17 21:41:50 +00:00
ExecutableFunctionImplPtr prepare(const ColumnsWithTypeAndName &) const override;
private:
2020-06-18 16:10:47 +00:00
TableLockHolder table_lock;
std::shared_ptr<HashJoinHolder> 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 {}; } // Not used
bool useDefaultImplementationForNulls() const override { return false; }
bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
bool isVariadic() const override { return true; }
size_t getNumberOfArguments() const override { return 0; }
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {0, 1}; }
private:
const Context & context;
};
}