1#include "ReverseBlockInputStream.h"
2
3#include <Common/PODArray.h>
4
5namespace DB
6{
7 ReverseBlockInputStream::ReverseBlockInputStream(const BlockInputStreamPtr & input)
8 {
9 children.push_back(input);
10 }
11
12 String ReverseBlockInputStream::getName() const
13 {
14 return "Reverse";
15 }
16
17 Block ReverseBlockInputStream::getHeader() const
18 {
19 return children.at(0)->getHeader();
20 }
21
22 Block ReverseBlockInputStream::readImpl()
23 {
24 auto result_block = children.back()->read();
25
26 if (!result_block)
27 {
28 return Block();
29 }
30
31 IColumn::Permutation permutation;
32
33 size_t rows_size = result_block.rows();
34 for (size_t i = 0; i < rows_size; ++i)
35 permutation.emplace_back(rows_size - 1 - i);
36
37 for (auto & block : result_block)
38 block.column = block.column->permute(permutation, 0);
39
40 return result_block;
41 }
42}
43