2017-04-27 17:16:24 +00:00
|
|
|
#pragma once
|
2018-08-24 05:20:18 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <memory>
|
2018-10-08 19:45:17 +00:00
|
|
|
#include <Columns/ColumnDecimal.h>
|
2017-04-27 17:16:24 +00:00
|
|
|
#include <Columns/ColumnString.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Columns/ColumnVector.h>
|
2017-04-28 18:33:31 +00:00
|
|
|
#include <Columns/IColumn.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Core/Names.h>
|
2017-04-28 18:33:31 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <common/logger_useful.h>
|
2018-11-28 11:37:12 +00:00
|
|
|
#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
|
|
|
|
2017-05-26 16:08:56 +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
|
|
|
*/
|
2021-08-04 17:58:18 +00:00
|
|
|
class DictionarySourceData
|
2017-04-27 17:16:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-08-04 17:58:18 +00:00
|
|
|
DictionarySourceData(
|
2021-03-24 16:31:00 +00:00
|
|
|
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
|
|
|
|
2021-08-04 17:58:18 +00:00
|
|
|
DictionarySourceData(
|
2021-03-24 16:31:00 +00:00
|
|
|
std::shared_ptr<const IDictionary> dictionary,
|
2021-02-16 21:33:02 +00:00
|
|
|
const PaddedPODArray<StringRef> & keys,
|
2018-12-10 15:25:45 +00:00
|
|
|
const Names & column_names);
|
2017-04-27 17:16:24 +00:00
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
using GetColumnsFunction = std::function<ColumnsWithTypeAndName(const Columns &, const std::vector<DictionaryAttribute> & attributes)>;
|
2018-08-24 05:37:06 +00:00
|
|
|
|
2017-06-05 09:02:05 +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
|
2017-06-05 09:02:05 +00:00
|
|
|
// 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
|
2021-08-04 17:58:18 +00:00
|
|
|
DictionarySourceData(
|
2021-03-24 16:31:00 +00:00
|
|
|
std::shared_ptr<const IDictionary> dictionary,
|
2018-12-10 15:25:45 +00:00
|
|
|
const Columns & data_columns,
|
|
|
|
const Names & column_names,
|
|
|
|
GetColumnsFunction && get_key_columns_function,
|
|
|
|
GetColumnsFunction && get_view_columns_function);
|
2017-06-05 09:02:05 +00:00
|
|
|
|
2021-08-04 17:58:18 +00:00
|
|
|
Block getBlock(size_t start, size_t length) const;
|
|
|
|
size_t getNumRows() const { return num_rows; }
|
2017-05-04 18:14:23 +00:00
|
|
|
|
2017-05-26 16:08:56 +00:00
|
|
|
private:
|
2021-03-24 16:31:00 +00:00
|
|
|
Block fillBlock(
|
|
|
|
const PaddedPODArray<UInt64> & ids_to_fill,
|
|
|
|
const Columns & keys,
|
|
|
|
const DataTypes & types,
|
|
|
|
ColumnsWithTypeAndName && view) const;
|
2017-05-04 18:14:23 +00:00
|
|
|
|
2021-03-24 16:31:00 +00:00
|
|
|
static ColumnPtr getColumnFromIds(const PaddedPODArray<UInt64> & ids_to_fill);
|
2017-05-04 18:14:23 +00:00
|
|
|
|
2021-03-24 16:31:00 +00:00
|
|
|
static void fillKeyColumns(
|
2021-02-16 21:33:02 +00:00
|
|
|
const PaddedPODArray<StringRef> & keys,
|
2018-12-10 15:25:45 +00:00
|
|
|
size_t start,
|
|
|
|
size_t size,
|
|
|
|
const DictionaryStructure & dictionary_structure,
|
2021-03-24 16:31:00 +00:00
|
|
|
ColumnsWithTypeAndName & result);
|
2017-05-04 18:14:23 +00:00
|
|
|
|
2021-08-04 17:58:18 +00:00
|
|
|
const size_t num_rows;
|
2021-03-24 16:31:00 +00:00
|
|
|
std::shared_ptr<const IDictionary> dictionary;
|
2017-05-26 16:08:56 +00:00
|
|
|
Names column_names;
|
2021-03-24 16:31:00 +00:00
|
|
|
PaddedPODArray<UInt64> ids;
|
2017-05-26 16:08:56 +00:00
|
|
|
ColumnsWithTypeAndName key_columns;
|
2018-08-24 05:37:06 +00:00
|
|
|
|
2017-06-05 09:02:05 +00:00
|
|
|
Columns data_columns;
|
|
|
|
GetColumnsFunction get_key_columns_function;
|
|
|
|
GetColumnsFunction get_view_columns_function;
|
2018-03-07 14:29:00 +00:00
|
|
|
|
2021-01-23 13:18:24 +00:00
|
|
|
enum class DictionaryInputStreamKeyType
|
2018-03-07 14:29:00 +00:00
|
|
|
{
|
|
|
|
Id,
|
|
|
|
ComplexKey,
|
|
|
|
Callback
|
|
|
|
};
|
|
|
|
|
2021-01-23 13:18:24 +00:00
|
|
|
DictionaryInputStreamKeyType key_type;
|
2017-04-27 17:16:24 +00:00
|
|
|
};
|
|
|
|
|
2021-08-04 17:58:18 +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;
|
|
|
|
};
|
|
|
|
|
2017-05-26 16:08:56 +00:00
|
|
|
}
|