2018-11-28 11:37:12 +00:00
|
|
|
#include "DictionarySourceHelpers.h"
|
2017-05-25 19:21:57 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Core/ColumnWithTypeAndName.h>
|
2017-05-25 19:21:57 +00:00
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2017-12-09 06:32:22 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include "DictionaryStructure.h"
|
2017-05-25 19:21:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/// For simple key
|
|
|
|
void formatIDs(BlockOutputStreamPtr & out, const std::vector<UInt64> & ids)
|
|
|
|
{
|
2017-12-14 01:43:19 +00:00
|
|
|
auto column = ColumnUInt64::create(ids.size());
|
2017-05-25 19:21:57 +00:00
|
|
|
memcpy(column->getData().data(), ids.data(), ids.size() * sizeof(ids.front()));
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
Block block{{std::move(column), std::make_shared<DataTypeUInt64>(), "id"}};
|
2017-05-25 19:21:57 +00:00
|
|
|
|
|
|
|
out->writePrefix();
|
|
|
|
out->write(block);
|
|
|
|
out->writeSuffix();
|
|
|
|
out->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// For composite key
|
2018-12-10 15:25:45 +00:00
|
|
|
void formatKeys(
|
|
|
|
const DictionaryStructure & dict_struct,
|
|
|
|
BlockOutputStreamPtr & out,
|
|
|
|
const Columns & key_columns,
|
|
|
|
const std::vector<size_t> & requested_rows)
|
2017-05-25 19:21:57 +00:00
|
|
|
{
|
|
|
|
Block block;
|
|
|
|
for (size_t i = 0, size = key_columns.size(); i < size; ++i)
|
2017-05-25 20:17:23 +00:00
|
|
|
{
|
|
|
|
const ColumnPtr & source_column = key_columns[i];
|
2017-12-15 03:04:33 +00:00
|
|
|
auto filtered_column = source_column->cloneEmpty();
|
2017-05-25 20:17:23 +00:00
|
|
|
filtered_column->reserve(requested_rows.size());
|
|
|
|
|
|
|
|
for (size_t idx : requested_rows)
|
|
|
|
filtered_column->insertFrom(*source_column, idx);
|
|
|
|
|
2018-12-10 15:25:45 +00:00
|
|
|
block.insert({std::move(filtered_column), (*dict_struct.key)[i].type, toString(i)});
|
2017-05-25 20:17:23 +00:00
|
|
|
}
|
2017-05-25 19:21:57 +00:00
|
|
|
|
|
|
|
out->writePrefix();
|
|
|
|
out->write(block);
|
|
|
|
out->writeSuffix();
|
|
|
|
out->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|