2017-11-20 06:01:05 +00:00
|
|
|
#include <Columns/Collator.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTOrderByElement.h>
|
2020-08-20 02:01:40 +00:00
|
|
|
#include <Common/SipHash.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-08-20 02:01:40 +00:00
|
|
|
void ASTOrderByElement::updateTreeHashImpl(SipHash & hash_state) const
|
|
|
|
{
|
|
|
|
hash_state.update(direction);
|
|
|
|
hash_state.update(nulls_direction);
|
|
|
|
hash_state.update(nulls_direction_was_explicitly_specified);
|
|
|
|
hash_state.update(with_fill);
|
|
|
|
IAST::updateTreeHashImpl(hash_state);
|
|
|
|
}
|
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
void ASTOrderByElement::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
children.front()->formatImpl(settings, state, frame);
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< (direction == -1 ? " DESC" : " ASC")
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (nulls_direction_was_explicitly_specified)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "")
|
|
|
|
<< " NULLS "
|
|
|
|
<< (nulls_direction == direction ? "LAST" : "FIRST")
|
|
|
|
<< (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
2017-03-12 12:56:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (collation)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " COLLATE " << (settings.hilite ? hilite_none : "");
|
|
|
|
collation->formatImpl(settings, state, frame);
|
|
|
|
}
|
2019-04-21 03:36:59 +00:00
|
|
|
|
|
|
|
if (with_fill)
|
|
|
|
{
|
2019-11-08 16:54:13 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " WITH FILL" << (settings.hilite ? hilite_none : "");
|
2019-04-21 03:36:59 +00:00
|
|
|
if (fill_from)
|
|
|
|
{
|
2019-11-08 16:54:13 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " FROM " << (settings.hilite ? hilite_none : "");
|
2019-04-21 03:36:59 +00:00
|
|
|
fill_from->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
if (fill_to)
|
|
|
|
{
|
2019-11-08 16:54:13 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " TO " << (settings.hilite ? hilite_none : "");
|
2019-04-21 03:36:59 +00:00
|
|
|
fill_to->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
if (fill_step)
|
|
|
|
{
|
2019-11-08 16:54:13 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " STEP " << (settings.hilite ? hilite_none : "");
|
2019-04-21 03:36:59 +00:00
|
|
|
fill_step->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
}
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|