ClickHouse/dbms/include/DB/Parsers/ASTOrderByElement.h

47 lines
1.4 KiB
C++
Raw Normal View History

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
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
*/
std::shared_ptr<Collator> collator;
2014-12-17 15:26:24 +00:00
ASTOrderByElement() = default;
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_) {}
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); }
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
children.front()->formatImpl(settings, state, frame);
settings.ostr << (settings.hilite ? hilite_keyword : "")
<< (direction == -1 ? " DESC" : " ASC")
<< (settings.hilite ? hilite_none : "");
if (collator)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " COLLATE " << (settings.hilite ? hilite_none : "")
<< "'" << collator->getLocale() << "'";
}
}
2011-09-04 05:14:52 +00:00
};
}