#pragma once #include namespace DB { class WriteBuffer; /// Takes a syntax tree and turns it into text. /// Intended for pretty-printing (multi-line + hiliting). /// In case of INSERT query, the data will be missing. void formatAST(const IAST & ast, WriteBuffer & buf, bool hilite = true, bool one_line = false, bool show_secrets = true); /// Like formatAST() but intended for serialization w/o pretty-printing (single-line, no hiliting). String serializeAST(const IAST & ast); inline WriteBuffer & operator<<(WriteBuffer & buf, const IAST & ast) { formatAST(ast, buf, false, true); return buf; } inline WriteBuffer & operator<<(WriteBuffer & buf, const ASTPtr & ast) { formatAST(*ast, buf, false, true); return buf; } } template<> struct fmt::formatter { template constexpr auto parse(ParseContext & context) { return context.begin(); } template auto format(const DB::ASTPtr & ast, FormatContext & context) { return fmt::format_to(context.out(), "{}", DB::serializeAST(*ast)); } };