2020-04-08 18:59:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Columns/ColumnVector.h>
|
2020-04-13 17:36:07 +00:00
|
|
|
#include <Functions/IFunctionAdaptors.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2020-04-08 18:59:52 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-04-13 17:36:07 +00:00
|
|
|
/// Read block of required columns from Dictionary by UInt64 key column. Rename columns if needed.
|
|
|
|
/// Current implementation uses dictHas() + N * dictGet() functions.
|
2020-04-08 18:59:52 +00:00
|
|
|
class DictionaryReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct FunctionWrapper
|
|
|
|
{
|
|
|
|
ExecutableFunctionPtr function;
|
|
|
|
ColumnNumbers arg_positions;
|
|
|
|
size_t result_pos = 0;
|
|
|
|
|
2020-04-10 10:28:44 +00:00
|
|
|
FunctionWrapper(FunctionOverloadResolverPtr resolver, const ColumnsWithTypeAndName & arguments, Block & block,
|
2020-04-13 17:36:07 +00:00
|
|
|
const ColumnNumbers & arg_positions_, const String & column_name, TypeIndex expected_type);
|
2020-04-08 18:59:52 +00:00
|
|
|
|
2020-10-09 07:41:28 +00:00
|
|
|
void execute(ColumnsWithTypeAndName & columns, size_t rows) const
|
2020-04-08 18:59:52 +00:00
|
|
|
{
|
2020-10-19 18:37:44 +00:00
|
|
|
ColumnsWithTypeAndName args;
|
|
|
|
args.reserve(arg_positions.size());
|
|
|
|
for (auto pos : arg_positions)
|
|
|
|
args.emplace_back(columns[pos]);
|
|
|
|
|
2020-10-20 13:11:57 +00:00
|
|
|
columns[result_pos].column = function->execute(args, columns[result_pos].type, rows, false);
|
2020-04-08 18:59:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DictionaryReader(const String & dictionary_name, const Names & src_column_names, const NamesAndTypesList & result_columns,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context);
|
2020-04-13 17:36:07 +00:00
|
|
|
void readKeys(const IColumn & keys, Block & out_block, ColumnVector<UInt8>::Container & found, std::vector<size_t> & positions) const;
|
2020-04-08 18:59:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Block result_header;
|
|
|
|
Block sample_block; /// dictionary name, column names, key, dictHas() result, dictGet() results
|
|
|
|
size_t key_position;
|
|
|
|
std::unique_ptr<FunctionWrapper> function_has;
|
|
|
|
std::vector<FunctionWrapper> functions_get;
|
|
|
|
|
2020-04-13 17:36:07 +00:00
|
|
|
static Block makeResultBlock(const NamesAndTypesList & names);
|
2020-04-08 18:59:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|