ClickHouse/src/Dictionaries/DictionaryBlockInputStream.h

103 lines
3.1 KiB
C++
Raw Normal View History

2017-04-27 17:16:24 +00:00
#pragma once
2018-08-24 05:20:18 +00:00
#include <memory>
#include <Columns/ColumnDecimal.h>
2017-04-27 17:16:24 +00:00
#include <Columns/ColumnString.h>
#include <Columns/ColumnVector.h>
2017-04-28 18:33:31 +00:00
#include <Columns/IColumn.h>
#include <Core/Names.h>
2017-04-28 18:33:31 +00:00
#include <DataTypes/DataTypesNumber.h>
#include <common/logger_useful.h>
#include "DictionaryBlockInputStreamBase.h"
#include "DictionaryStructure.h"
#include "IDictionary.h"
2017-04-27 17:16:24 +00:00
2021-07-17 18:06:46 +00:00
namespace DB
2017-04-28 18:33:31 +00:00
{
2018-06-05 19:46:49 +00:00
2021-02-16 21:33:02 +00:00
/// TODO: Remove this class
2018-08-24 05:37:06 +00:00
/* BlockInputStream implementation for external dictionaries
* read() returns blocks consisting of the in-memory contents of the dictionaries
2017-04-27 17:16:24 +00:00
*/
class DictionarySourceData
2017-04-27 17:16:24 +00:00
{
public:
DictionarySourceData(
std::shared_ptr<const IDictionary> dictionary,
PaddedPODArray<UInt64> && ids,
2021-02-16 21:33:02 +00:00
const Names & column_names);
2018-08-24 05:37:06 +00:00
DictionarySourceData(
std::shared_ptr<const IDictionary> dictionary,
2021-02-16 21:33:02 +00:00
const PaddedPODArray<StringRef> & keys,
const Names & column_names);
2017-04-27 17:16:24 +00:00
using GetColumnsFunction = std::function<ColumnsWithTypeAndName(const Columns &, const std::vector<DictionaryAttribute> & attributes)>;
2018-08-24 05:37:06 +00:00
// Used to separate key columns format for storage and view.
2020-01-11 09:50:41 +00:00
// Calls get_key_columns_function to get key column for dictionary get function call
// and get_view_columns_function to get key representation.
// Now used in trie dictionary, where columns are stored as ip and mask, and are showed as string
DictionarySourceData(
std::shared_ptr<const IDictionary> dictionary,
const Columns & data_columns,
const Names & column_names,
GetColumnsFunction && get_key_columns_function,
GetColumnsFunction && get_view_columns_function);
Block getBlock(size_t start, size_t length) const;
size_t getNumRows() const { return num_rows; }
private:
Block fillBlock(
const PaddedPODArray<UInt64> & ids_to_fill,
const Columns & keys,
const DataTypes & types,
ColumnsWithTypeAndName && view) const;
static ColumnPtr getColumnFromIds(const PaddedPODArray<UInt64> & ids_to_fill);
static void fillKeyColumns(
2021-02-16 21:33:02 +00:00
const PaddedPODArray<StringRef> & keys,
size_t start,
size_t size,
const DictionaryStructure & dictionary_structure,
ColumnsWithTypeAndName & result);
const size_t num_rows;
std::shared_ptr<const IDictionary> dictionary;
Names column_names;
PaddedPODArray<UInt64> ids;
ColumnsWithTypeAndName key_columns;
2018-08-24 05:37:06 +00:00
Columns data_columns;
GetColumnsFunction get_key_columns_function;
GetColumnsFunction get_view_columns_function;
enum class DictionaryInputStreamKeyType
{
Id,
ComplexKey,
Callback
};
DictionaryInputStreamKeyType key_type;
2017-04-27 17:16:24 +00:00
};
class DictionarySource final : public DictionarySourceBase
{
public:
DictionarySource(DictionarySourceData data_, UInt64 max_block_size)
: DictionarySourceBase(data_.getBlock(0, 0), data_.getNumRows(), max_block_size)
, data(std::move(data_))
{}
String getName() const override { return "DictionarySource"; }
Block getBlock(size_t start, size_t length) const override { return data.getBlock(start, length); }
DictionarySourceData data;
};
}