| 1 | #include <Parsers/ASTQueryWithOutput.h> |
| 2 | |
| 3 | namespace DB |
| 4 | { |
| 5 | |
| 6 | void ASTQueryWithOutput::cloneOutputOptions(ASTQueryWithOutput & cloned) const |
| 7 | { |
| 8 | if (out_file) |
| 9 | { |
| 10 | cloned.out_file = out_file->clone(); |
| 11 | cloned.children.push_back(cloned.out_file); |
| 12 | } |
| 13 | if (format) |
| 14 | { |
| 15 | cloned.format = format->clone(); |
| 16 | cloned.children.push_back(cloned.format); |
| 17 | } |
| 18 | if (settings_ast) |
| 19 | { |
| 20 | cloned.settings_ast = settings_ast->clone(); |
| 21 | cloned.children.push_back(cloned.settings_ast); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | void ASTQueryWithOutput::formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const |
| 26 | { |
| 27 | formatQueryImpl(s, state, frame); |
| 28 | |
| 29 | std::string indent_str = s.one_line ? "" : std::string(4u * frame.indent, ' '); |
| 30 | |
| 31 | if (out_file) |
| 32 | { |
| 33 | s.ostr << (s.hilite ? hilite_keyword : "" ) << s.nl_or_ws << indent_str << "INTO OUTFILE " << (s.hilite ? hilite_none : "" ); |
| 34 | out_file->formatImpl(s, state, frame); |
| 35 | } |
| 36 | |
| 37 | if (format) |
| 38 | { |
| 39 | s.ostr << (s.hilite ? hilite_keyword : "" ) << s.nl_or_ws << indent_str << "FORMAT " << (s.hilite ? hilite_none : "" ); |
| 40 | format->formatImpl(s, state, frame); |
| 41 | } |
| 42 | |
| 43 | if (settings_ast) |
| 44 | { |
| 45 | s.ostr << (s.hilite ? hilite_keyword : "" ) << s.nl_or_ws << indent_str << "SETTINGS " << (s.hilite ? hilite_none : "" ); |
| 46 | settings_ast->formatImpl(s, state, frame); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | bool ASTQueryWithOutput::resetOutputASTIfExist(IAST & ast) |
| 51 | { |
| 52 | /// FIXME: try to prettify this cast using `as<>()` |
| 53 | if (auto * ast_with_output = dynamic_cast<ASTQueryWithOutput *>(&ast)) |
| 54 | { |
| 55 | ast_with_output->format.reset(); |
| 56 | ast_with_output->out_file.reset(); |
| 57 | ast_with_output->settings_ast.reset(); |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | } |
| 66 | |