ClickHouse/src/Dictionaries/DictionaryBlockInputStream.h

93 lines
2.8 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>
#include <DataStreams/IBlockInputStream.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
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
*/
2017-04-28 18:33:31 +00:00
class DictionaryBlockInputStream : public DictionaryBlockInputStreamBase
2017-04-27 17:16:24 +00:00
{
public:
DictionaryBlockInputStream(
std::shared_ptr<const IDictionary> dictionary,
2021-02-16 21:33:02 +00:00
UInt64 max_block_size,
PaddedPODArray<UInt64> && ids,
2021-02-16 21:33:02 +00:00
const Names & column_names);
2018-08-24 05:37:06 +00:00
DictionaryBlockInputStream(
std::shared_ptr<const IDictionary> dictionary,
2019-02-10 16:55:12 +00:00
UInt64 max_block_size,
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
DictionaryBlockInputStream(
std::shared_ptr<const IDictionary> dictionary,
2019-02-10 16:55:12 +00:00
UInt64 max_block_size,
const Columns & data_columns,
const Names & column_names,
GetColumnsFunction && get_key_columns_function,
GetColumnsFunction && get_view_columns_function);
String getName() const override { return "Dictionary"; }
2017-04-27 17:16:24 +00:00
protected:
2021-02-16 21:33:02 +00:00
Block getBlock(size_t start, size_t length) const override;
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);
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
};
}