2020-10-10 18:37:02 +00:00
|
|
|
#pragma once
|
2021-04-10 23:33:54 +00:00
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
#include <Functions/IFunction.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2020-06-22 09:49:21 +00:00
|
|
|
#include <Storages/TableLockHolder.h>
|
2020-10-09 07:41:28 +00:00
|
|
|
#include <Core/Block.h>
|
2018-11-30 14:49:35 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-09-09 19:43:37 +00:00
|
|
|
|
2020-04-07 09:48:47 +00:00
|
|
|
class HashJoin;
|
2021-02-25 09:31:22 +00:00
|
|
|
class StorageJoin;
|
|
|
|
using StorageJoinPtr = std::shared_ptr<StorageJoin>;
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2020-04-07 14:52:32 +00:00
|
|
|
template <bool or_null>
|
2021-09-29 17:30:07 +00:00
|
|
|
class ExecutableFunctionJoinGet final : public IExecutableFunction, WithContext
|
2018-11-30 14:49:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-09-29 17:30:07 +00:00
|
|
|
ExecutableFunctionJoinGet(ContextPtr context_,
|
|
|
|
TableLockHolder table_lock_,
|
2021-02-25 11:21:06 +00:00
|
|
|
StorageJoinPtr storage_join_,
|
|
|
|
const DB::Block & result_columns_)
|
2021-09-29 17:30:07 +00:00
|
|
|
: WithContext(context_)
|
|
|
|
, table_lock(std::move(table_lock_))
|
2021-02-25 11:21:06 +00:00
|
|
|
, 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";
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2020-02-05 13:51:41 +00:00
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
2021-07-09 09:16:03 +00:00
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
|
2020-07-11 07:12:42 +00:00
|
|
|
bool useDefaultImplementationForConstants() const override { return true; }
|
2020-02-05 13:51:41 +00:00
|
|
|
|
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:
|
2021-02-25 11:21:06 +00:00
|
|
|
TableLockHolder table_lock;
|
2021-02-25 09:31:22 +00:00
|
|
|
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>
|
2021-09-29 17:30:07 +00:00
|
|
|
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
|
|
|
|
2021-09-29 17:30:07 +00:00
|
|
|
FunctionJoinGet(ContextPtr context_,
|
|
|
|
TableLockHolder table_lock_,
|
2021-02-25 09:31:22 +00:00
|
|
|
StorageJoinPtr storage_join_, String attr_name_,
|
2019-12-09 14:41:55 +00:00
|
|
|
DataTypes argument_types_, DataTypePtr return_type_)
|
2021-09-29 17:30:07 +00:00
|
|
|
: WithContext(context_)
|
|
|
|
, table_lock(std::move(table_lock_))
|
2021-02-25 09:31:22 +00:00
|
|
|
, 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
|
|
|
{
|
|
|
|
}
|
2018-11-30 14:49:35 +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; }
|
2021-04-29 14:48:26 +00:00
|
|
|
|
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; }
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2021-05-15 17:33:15 +00:00
|
|
|
ExecutableFunctionPtr prepare(const ColumnsWithTypeAndName &) const override;
|
2018-11-30 14:49:35 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-18 16:10:47 +00:00
|
|
|
TableLockHolder table_lock;
|
2021-02-25 09:31:22 +00:00
|
|
|
StorageJoinPtr storage_join;
|
2018-11-30 14:49:35 +00:00
|
|
|
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;
|
2018-11-30 14:49:35 +00:00
|
|
|
};
|
|
|
|
|
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
|
2018-11-30 14:49:35 +00:00
|
|
|
{
|
|
|
|
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_); }
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2021-06-01 12:20:52 +00:00
|
|
|
explicit JoinGetOverloadResolver(ContextPtr context_) : WithContext(context_) {}
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2023-05-12 16:35:06 +00:00
|
|
|
bool isDeterministic() const override { return false; }
|
2018-11-30 14:49:35 +00:00
|
|
|
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
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2020-02-05 13:51:41 +00:00
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
2020-09-24 08:38:57 +00:00
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const override { return false; }
|
2020-02-05 13:51:41 +00:00
|
|
|
|
2018-11-30 14:49:35 +00:00
|
|
|
bool isVariadic() const override { return true; }
|
|
|
|
size_t getNumberOfArguments() const override { return 0; }
|
2020-07-11 07:12:42 +00:00
|
|
|
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {0, 1}; }
|
2018-11-30 14:49:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|