2019-09-02 14:29:51 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Core/SortDescription.h>
|
2022-03-17 05:51:35 +00:00
|
|
|
#include <Core/InterpolateDescription.h>
|
2019-09-02 14:29:51 +00:00
|
|
|
#include <Columns/IColumn.h>
|
2020-06-14 18:42:10 +00:00
|
|
|
|
2019-09-02 14:29:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Compares fields in terms of sorting order, considering direction.
|
|
|
|
bool less(const Field & lhs, const Field & rhs, int direction);
|
|
|
|
bool equals(const Field & lhs, const Field & rhs);
|
|
|
|
|
2019-09-02 17:18:44 +00:00
|
|
|
/** Helps to implement modifier WITH FILL for ORDER BY clause.
|
2019-09-02 15:22:27 +00:00
|
|
|
* Stores row as array of fields and provides functions to generate next row for filling gaps and for comparing rows.
|
|
|
|
* Used in FillingBlockInputStream and in FillingTransform.
|
|
|
|
*/
|
2019-09-02 14:29:51 +00:00
|
|
|
class FillingRow
|
|
|
|
{
|
|
|
|
public:
|
2022-03-17 06:31:01 +00:00
|
|
|
struct
|
|
|
|
{
|
2022-03-17 05:51:35 +00:00
|
|
|
FillingRow & filling_row;
|
|
|
|
|
|
|
|
Field & operator[](size_t index) { return filling_row.row[index]; }
|
|
|
|
const Field & operator[](size_t index) const { return filling_row.row[index]; }
|
|
|
|
size_t size() const { return filling_row.sort_description.size(); }
|
|
|
|
} sort;
|
|
|
|
|
2022-03-17 06:31:01 +00:00
|
|
|
struct
|
|
|
|
{
|
2022-03-17 05:51:35 +00:00
|
|
|
FillingRow & filling_row;
|
|
|
|
|
|
|
|
Field & operator[](size_t index) { return filling_row.row[filling_row.sort_description.size() + index]; }
|
|
|
|
const Field & operator[](size_t index) const { return filling_row.row[filling_row.sort_description.size() + index]; }
|
|
|
|
size_t size() const { return filling_row.interpolate_description.size(); }
|
|
|
|
} interpolate;
|
|
|
|
public:
|
|
|
|
FillingRow(const SortDescription & sort_description, const InterpolateDescription & interpolate_description);
|
2019-09-02 14:29:51 +00:00
|
|
|
|
|
|
|
/// Generates next row according to fill 'from', 'to' and 'step' values.
|
|
|
|
bool next(const FillingRow & to_row);
|
|
|
|
|
|
|
|
void initFromDefaults(size_t from_pos = 0);
|
|
|
|
|
2021-09-11 23:55:53 +00:00
|
|
|
Field & operator[](size_t index) { return row[index]; }
|
|
|
|
const Field & operator[](size_t index) const { return row[index]; }
|
2019-09-02 14:29:51 +00:00
|
|
|
size_t size() const { return row.size(); }
|
|
|
|
bool operator<(const FillingRow & other) const;
|
|
|
|
bool operator==(const FillingRow & other) const;
|
|
|
|
|
2022-03-17 05:51:35 +00:00
|
|
|
int getDirection(size_t index) const { return sort_description[index].direction; }
|
|
|
|
FillColumnDescription & getFillDescription(size_t index) { return sort_description[index].fill_description; }
|
|
|
|
InterpolateColumnDescription & getInterpolateDescription(size_t index) { return interpolate_description[index]; }
|
2019-09-02 14:29:51 +00:00
|
|
|
|
|
|
|
private:
|
2021-05-21 01:17:18 +00:00
|
|
|
Row row;
|
2022-03-17 05:51:35 +00:00
|
|
|
SortDescription sort_description;
|
|
|
|
InterpolateDescription interpolate_description;
|
2019-09-02 14:29:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void insertFromFillingRow(MutableColumns & filling_columns, MutableColumns & other_columns, const FillingRow & filling_row);
|
|
|
|
void copyRowFromColumns(MutableColumns & dest, const Columns & source, size_t row_num);
|
|
|
|
|
2019-09-02 17:18:44 +00:00
|
|
|
}
|