2011-09-04 05:14:52 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/Parsers/IAST.h>
|
2013-05-28 16:56:05 +00:00
|
|
|
|
#include <DB/Common/Collator.h>
|
2011-09-04 05:14:52 +00:00
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Элемент выражения, после которого стоит ASC или DESC
|
|
|
|
|
*/
|
|
|
|
|
class ASTOrderByElement : public IAST
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
int direction; /// 1, если ASC, -1, если DESC
|
2016-05-28 14:14:18 +00:00
|
|
|
|
|
2013-05-28 16:56:05 +00:00
|
|
|
|
/** Collator для locale-specific сортировки строк.
|
2014-04-08 07:58:53 +00:00
|
|
|
|
* Если nullptr, то производится сортировка по байтам.
|
2013-05-28 16:56:05 +00:00
|
|
|
|
*/
|
2016-05-28 14:14:18 +00:00
|
|
|
|
std::shared_ptr<Collator> collator;
|
|
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
|
ASTOrderByElement() = default;
|
2016-05-28 14:14:18 +00:00
|
|
|
|
ASTOrderByElement(const StringRange range_, const int direction_, const std::shared_ptr<Collator> & collator_ = nullptr)
|
2013-05-28 16:56:05 +00:00
|
|
|
|
: IAST(range_), direction(direction_), collator(collator_) {}
|
2016-05-28 14:14:18 +00:00
|
|
|
|
|
2011-09-04 05:14:52 +00:00
|
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
2014-12-17 15:26:24 +00:00
|
|
|
|
String getID() const override { return "OrderByElement"; }
|
2011-12-12 06:15:34 +00:00
|
|
|
|
|
2014-12-17 15:26:24 +00:00
|
|
|
|
ASTPtr clone() const override { return new ASTOrderByElement(*this); }
|
2015-08-05 21:38:31 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
|
|
|
|
|
{
|
|
|
|
|
children.front()->formatImpl(settings, state, frame);
|
2016-05-28 14:14:18 +00:00
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
|
<< (direction == -1 ? " DESC" : " ASC")
|
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
|
|
|
|
|
|
if (collator)
|
2015-08-05 21:38:31 +00:00
|
|
|
|
{
|
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " COLLATE " << (settings.hilite ? hilite_none : "")
|
|
|
|
|
<< "'" << collator->getLocale() << "'";
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-04 05:14:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|