1#pragma once
2#include <Processors/ISimpleTransform.h>
3#include <Core/SortDescription.h>
4#include <Interpreters/FillingRow.h>
5
6namespace DB
7{
8
9/** Implements modifier WITH FILL of ORDER BY clause.
10 * It fills gaps in data stream by rows with missing values in columns with set WITH FILL and deafult values in other columns.
11 * Optionally FROM, TO and STEP values can be specified.
12 */
13class FillingTransform : public ISimpleTransform
14{
15public:
16 FillingTransform(const Block & header_, const SortDescription & fill_description_);
17
18 String getName() const override { return "FillingTransform"; }
19
20 Status prepare() override;
21
22protected:
23 void transform(Chunk & Chunk) override;
24
25private:
26 void setResultColumns(Chunk & chunk, MutableColumns & fill_columns, MutableColumns & other_columns) const;
27
28 const SortDescription sort_description; /// Contains only rows with WITH FILL.
29 FillingRow filling_row; /// Current row, which is used to fill gaps.
30 FillingRow next_row; /// Row to which we need to generate filling rows.
31
32 using Positions = std::vector<size_t>;
33 Positions fill_column_positions;
34 Positions other_column_positions;
35 bool first = true;
36 bool generate_suffix = false;
37
38 /// Determines should we insert filling row before start generating next rows.
39 bool should_insert_first = false;
40};
41
42}
43