1#include <Parsers/ASTSubquery.h>
2#include <IO/WriteHelpers.h>
3
4namespace DB
5{
6
7void ASTSubquery::appendColumnNameImpl(WriteBuffer & ostr) const
8{
9 /// This is a hack. We use alias, if available, because otherwise tree could change during analysis.
10 if (!alias.empty())
11 {
12 writeString(alias, ostr);
13 }
14 else
15 {
16 Hash hash = getTreeHash();
17 writeCString("__subquery_", ostr);
18 writeText(hash.first, ostr);
19 ostr.write('_');
20 writeText(hash.second, ostr);
21 }
22}
23
24void ASTSubquery::formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
25{
26 std::string indent_str = settings.one_line ? "" : std::string(4u * frame.indent, ' ');
27 std::string nl_or_nothing = settings.one_line ? "" : "\n";
28
29 settings.ostr << nl_or_nothing << indent_str << "(" << nl_or_nothing;
30 FormatStateStacked frame_nested = frame;
31 frame_nested.need_parens = false;
32 ++frame_nested.indent;
33 children[0]->formatImpl(settings, state, frame_nested);
34 settings.ostr << nl_or_nothing << indent_str << ")";
35}
36
37}
38
39