2020-10-10 18:37:02 +00:00
|
|
|
#pragma once
|
2019-12-09 13:12:54 +00:00
|
|
|
#include <Functions/IFunctionImpl.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
|
|
|
|
2018-11-30 14:49:35 +00:00
|
|
|
class Context;
|
2020-04-07 09:48:47 +00:00
|
|
|
class HashJoin;
|
|
|
|
using HashJoinPtr = std::shared_ptr<HashJoin>;
|
2018-11-30 14:49:35 +00:00
|
|
|
|
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
|
2018-11-30 14:49:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-10-09 07:41:28 +00:00
|
|
|
ExecutableFunctionJoinGet(HashJoinPtr join_, const DB::Block & result_block_)
|
2020-07-11 07:12:42 +00:00
|
|
|
: 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";
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2020-02-05 13:51:41 +00:00
|
|
|
bool useDefaultImplementationForNulls() const override { return false; }
|
2020-07-23 07:47:17 +00:00
|
|
|
bool useDefaultImplementationForLowCardinalityColumns() const override { return true; }
|
2020-07-11 07:12:42 +00:00
|
|
|
bool useDefaultImplementationForConstants() const override { return true; }
|
2020-02-05 13:51:41 +00:00
|
|
|
|
2020-10-14 13:09:11 +00:00
|
|
|
void execute(ColumnsWithTypeAndName & block, const ColumnNumbers & arguments, size_t result, size_t input_rows_count) override;
|
2019-12-09 14:41:55 +00:00
|
|
|
|
|
|
|
String getName() const override { return name; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
HashJoinPtr join;
|
2020-10-09 07:41:28 +00:00
|
|
|
DB::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
|
|
|
{
|
|
|
|
}
|
2018-11-30 14:49:35 +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; }
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2020-10-14 13:09:11 +00:00
|
|
|
ExecutableFunctionImplPtr prepare(const ColumnsWithTypeAndName & sample_block, const ColumnNumbers & arguments, size_t result) const override;
|
2018-11-30 14:49:35 +00:00
|
|
|
|
|
|
|
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;
|
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>
|
2019-12-12 14:16:59 +00:00
|
|
|
class JoinGetOverloadResolver final : public IFunctionOverloadResolverImpl
|
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";
|
2019-12-12 14:16:59 +00:00
|
|
|
static FunctionOverloadResolverImplPtr create(const Context & context) { return std::make_unique<JoinGetOverloadResolver>(context); }
|
2018-11-30 14:49:35 +00:00
|
|
|
|
2019-12-12 14:16:59 +00:00
|
|
|
explicit JoinGetOverloadResolver(const Context & context_) : context(context_) {}
|
2018-11-30 14:49:35 +00:00
|
|
|
|
|
|
|
String getName() const override { return name; }
|
|
|
|
|
2019-12-09 14:41:55 +00:00
|
|
|
FunctionBaseImplPtr build(const ColumnsWithTypeAndName & arguments, const DataTypePtr &) const override;
|
2020-07-11 07:12:42 +00:00
|
|
|
DataTypePtr getReturnType(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
|
|
|
|
|
|
|
private:
|
|
|
|
const Context & context;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|