2017-07-26 01:21:19 +00:00
|
|
|
#include <Parsers/ASTSubquery.h>
|
2018-02-23 08:05:21 +00:00
|
|
|
#include <IO/WriteHelpers.h>
|
2017-07-26 01:21:19 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-06-27 16:34:11 +00:00
|
|
|
void ASTSubquery::appendColumnNameImpl(WriteBuffer & ostr) const
|
2017-07-26 01:21:19 +00:00
|
|
|
{
|
2018-02-23 11:35:05 +00:00
|
|
|
/// This is a hack. We use alias, if available, because otherwise tree could change during analysis.
|
|
|
|
if (!alias.empty())
|
2018-09-10 03:59:48 +00:00
|
|
|
{
|
2018-06-27 16:34:11 +00:00
|
|
|
writeString(alias, ostr);
|
2018-09-10 03:59:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Hash hash = getTreeHash();
|
|
|
|
writeCString("__subquery_", ostr);
|
|
|
|
writeText(hash.first, ostr);
|
|
|
|
ostr.write('_');
|
|
|
|
writeText(hash.second, ostr);
|
|
|
|
}
|
2018-06-27 16:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTSubquery::formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
std::string indent_str = settings.one_line ? "" : std::string(4u * frame.indent, ' ');
|
|
|
|
std::string nl_or_nothing = settings.one_line ? "" : "\n";
|
|
|
|
|
|
|
|
settings.ostr << nl_or_nothing << indent_str << "(" << nl_or_nothing;
|
|
|
|
FormatStateStacked frame_nested = frame;
|
|
|
|
frame_nested.need_parens = false;
|
|
|
|
++frame_nested.indent;
|
|
|
|
children[0]->formatImpl(settings, state, frame_nested);
|
|
|
|
settings.ostr << nl_or_nothing << indent_str << ")";
|
2017-07-26 01:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|