2011-09-04 01:42:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
2017-03-12 12:56:59 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <cstddef>
|
2017-03-16 15:04:05 +00:00
|
|
|
#include <string>
|
2019-04-23 01:48:51 +00:00
|
|
|
#include <Core/Field.h>
|
2020-07-16 22:01:08 +00:00
|
|
|
#include <Core/SettingsEnums.h>
|
2011-09-04 01:42:14 +00:00
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
class Collator;
|
|
|
|
|
2011-09-04 01:42:14 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-04-16 16:36:59 +00:00
|
|
|
namespace JSONBuilder
|
|
|
|
{
|
|
|
|
class JSONMap;
|
|
|
|
class IItem;
|
|
|
|
using ItemPtr = std::unique_ptr<IItem>;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Block;
|
|
|
|
|
2019-04-21 23:04:23 +00:00
|
|
|
struct FillColumnDescription
|
|
|
|
{
|
2019-08-19 20:22:45 +00:00
|
|
|
/// All missed values in range [FROM, TO) will be filled
|
|
|
|
/// Range [FROM, TO) respects sorting direction
|
2019-04-21 23:04:23 +00:00
|
|
|
Field fill_from; /// Fill value >= FILL_FROM
|
2019-08-19 20:22:45 +00:00
|
|
|
Field fill_to; /// Fill value + STEP < FILL_TO
|
|
|
|
Field fill_step; /// Default = 1 or -1 according to direction
|
2019-04-21 23:04:23 +00:00
|
|
|
};
|
|
|
|
|
2017-04-30 13:50:16 +00:00
|
|
|
/// Description of the sorting rule by one column.
|
2011-09-04 01:42:14 +00:00
|
|
|
struct SortColumnDescription
|
|
|
|
{
|
2017-09-08 02:29:47 +00:00
|
|
|
std::string column_name; /// The name of the column.
|
|
|
|
size_t column_number; /// Column number (used if no name is given).
|
|
|
|
int direction; /// 1 - ascending, -1 - descending.
|
|
|
|
int nulls_direction; /// 1 - NULLs and NaNs are greater, -1 - less.
|
|
|
|
/// To achieve NULLS LAST, set it equal to direction, to achieve NULLS FIRST, set it opposite.
|
|
|
|
std::shared_ptr<Collator> collator; /// Collator for locale-specific comparison of strings
|
2019-04-21 23:04:23 +00:00
|
|
|
bool with_fill;
|
|
|
|
FillColumnDescription fill_description;
|
2019-04-21 03:36:59 +00:00
|
|
|
|
|
|
|
SortColumnDescription(
|
|
|
|
size_t column_number_, int direction_, int nulls_direction_,
|
2020-09-19 14:20:00 +00:00
|
|
|
const std::shared_ptr<Collator> & collator_ = nullptr,
|
2020-05-15 00:01:14 +00:00
|
|
|
bool with_fill_ = false, const FillColumnDescription & fill_description_ = {})
|
2019-04-21 03:36:59 +00:00
|
|
|
: column_number(column_number_), direction(direction_), nulls_direction(nulls_direction_), collator(collator_)
|
2020-09-19 14:20:00 +00:00
|
|
|
, with_fill(with_fill_), fill_description(fill_description_) {}
|
2019-04-21 03:36:59 +00:00
|
|
|
|
|
|
|
SortColumnDescription(
|
|
|
|
const std::string & column_name_, int direction_, int nulls_direction_,
|
2020-09-19 14:20:00 +00:00
|
|
|
const std::shared_ptr<Collator> & collator_ = nullptr,
|
2020-05-15 00:01:14 +00:00
|
|
|
bool with_fill_ = false, const FillColumnDescription & fill_description_ = {})
|
2019-04-21 03:36:59 +00:00
|
|
|
: column_name(column_name_), column_number(0), direction(direction_), nulls_direction(nulls_direction_)
|
2020-09-19 14:20:00 +00:00
|
|
|
, collator(collator_), with_fill(with_fill_), fill_description(fill_description_) {}
|
2018-10-19 12:02:31 +00:00
|
|
|
|
|
|
|
bool operator == (const SortColumnDescription & other) const
|
|
|
|
{
|
|
|
|
return column_name == other.column_name && column_number == other.column_number
|
|
|
|
&& direction == other.direction && nulls_direction == other.nulls_direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const SortColumnDescription & other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2020-05-05 14:35:23 +00:00
|
|
|
|
2020-05-07 15:37:19 +00:00
|
|
|
std::string dump() const
|
|
|
|
{
|
2020-11-10 18:22:26 +00:00
|
|
|
return fmt::format("{}:{}:dir {}nulls ", column_name, column_number, direction, nulls_direction);
|
2020-05-05 14:35:23 +00:00
|
|
|
}
|
2021-04-16 16:36:59 +00:00
|
|
|
|
|
|
|
void explain(JSONBuilder::JSONMap & map, const Block & header) const;
|
2011-09-04 01:42:14 +00:00
|
|
|
};
|
|
|
|
|
2017-04-30 13:50:16 +00:00
|
|
|
/// Description of the sorting rule for several columns.
|
2016-05-28 10:35:44 +00:00
|
|
|
using SortDescription = std::vector<SortColumnDescription>;
|
2011-09-04 01:42:14 +00:00
|
|
|
|
2020-07-05 16:26:57 +00:00
|
|
|
/// Outputs user-readable description into `out`.
|
2020-06-27 14:02:24 +00:00
|
|
|
void dumpSortDescription(const SortDescription & description, const Block & header, WriteBuffer & out);
|
2020-06-24 12:09:01 +00:00
|
|
|
|
2020-12-10 19:06:52 +00:00
|
|
|
std::string dumpSortDescription(const SortDescription & description);
|
|
|
|
|
2021-04-16 16:36:59 +00:00
|
|
|
JSONBuilder::ItemPtr explainSortDescription(const SortDescription & description, const Block & header);
|
|
|
|
|
2011-09-04 01:42:14 +00:00
|
|
|
}
|