ClickHouse/src/Functions/FunctionJoinGet.h

105 lines
3.7 KiB
C++
Raw Normal View History

2020-10-10 18:37:02 +00:00
#pragma once
2021-05-15 17:33:15 +00:00
#include <Functions/IFunction.h>
#include <Interpreters/Context_fwd.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 HashJoin;
class StorageJoin;
using StorageJoinPtr = std::shared_ptr<StorageJoin>;
2020-04-07 14:52:32 +00:00
template <bool or_null>
class ExecutableFunctionJoinGet final : public IExecutableFunction, WithContext
{
public:
ExecutableFunctionJoinGet(ContextPtr context_,
TableLockHolder table_lock_,
StorageJoinPtr storage_join_,
const DB::Block & result_columns_)
: WithContext(context_)
, table_lock(std::move(table_lock_))
, storage_join(std::move(storage_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 false; }
bool useDefaultImplementationForConstants() const override { return true; }
2021-05-15 17:33:15 +00:00
ColumnPtr executeImpl(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:
TableLockHolder table_lock;
StorageJoinPtr storage_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>
class FunctionJoinGet final : public IFunctionBase, WithContext
2019-12-09 14:41:55 +00:00
{
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(ContextPtr context_,
TableLockHolder table_lock_,
StorageJoinPtr storage_join_, String attr_name_,
2019-12-09 14:41:55 +00:00
DataTypes argument_types_, DataTypePtr return_type_)
: WithContext(context_)
, table_lock(std::move(table_lock_))
, storage_join(storage_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; }
2021-06-22 16:21:23 +00:00
bool isSuitableForShortCircuitArgumentsExecution(const DataTypesWithConstInfo & /*arguments*/) const override { return true; }
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; }
2021-05-15 17:33:15 +00:00
ExecutableFunctionPtr prepare(const ColumnsWithTypeAndName &) const override;
private:
2020-06-18 16:10:47 +00:00
TableLockHolder table_lock;
StorageJoinPtr storage_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>
2021-06-01 12:20:52 +00:00
class JoinGetOverloadResolver final : public IFunctionOverloadResolver, WithContext
{
public:
2020-04-07 14:52:32 +00:00
static constexpr auto name = or_null ? "joinGetOrNull" : "joinGet";
2021-06-01 12:20:52 +00:00
static FunctionOverloadResolverPtr create(ContextPtr context_) { return std::make_unique<JoinGetOverloadResolver>(context_); }
2021-06-01 12:20:52 +00:00
explicit JoinGetOverloadResolver(ContextPtr context_) : WithContext(context_) {}
String getName() const override { return name; }
2021-05-15 17:33:15 +00:00
FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr &) const override;
DataTypePtr getReturnTypeImpl(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}; }
};
}