1#include "DictionarySourceHelpers.h"
2#include <Columns/ColumnsNumber.h>
3#include <Core/Block.h>
4#include <Core/ColumnWithTypeAndName.h>
5#include <DataStreams/IBlockOutputStream.h>
6#include <DataTypes/DataTypesNumber.h>
7#include <IO/WriteHelpers.h>
8#include "DictionaryStructure.h"
9
10
11namespace DB
12{
13/// For simple key
14void formatIDs(BlockOutputStreamPtr & out, const std::vector<UInt64> & ids)
15{
16 auto column = ColumnUInt64::create(ids.size());
17 memcpy(column->getData().data(), ids.data(), ids.size() * sizeof(ids.front()));
18
19 Block block{{std::move(column), std::make_shared<DataTypeUInt64>(), "id"}};
20
21 out->writePrefix();
22 out->write(block);
23 out->writeSuffix();
24 out->flush();
25}
26
27/// For composite key
28void formatKeys(
29 const DictionaryStructure & dict_struct,
30 BlockOutputStreamPtr & out,
31 const Columns & key_columns,
32 const std::vector<size_t> & requested_rows)
33{
34 Block block;
35 for (size_t i = 0, size = key_columns.size(); i < size; ++i)
36 {
37 const ColumnPtr & source_column = key_columns[i];
38 auto filtered_column = source_column->cloneEmpty();
39 filtered_column->reserve(requested_rows.size());
40
41 for (size_t idx : requested_rows)
42 filtered_column->insertFrom(*source_column, idx);
43
44 block.insert({std::move(filtered_column), (*dict_struct.key)[i].type, toString(i)});
45 }
46
47 out->writePrefix();
48 out->write(block);
49 out->writeSuffix();
50 out->flush();
51}
52
53}
54