diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 09:58:56 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 10:20:20 +0300 |
commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/Parsers/formatAST.h | |
parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
download | ydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/Parsers/formatAST.h')
-rw-r--r-- | contrib/clickhouse/src/Parsers/formatAST.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/Parsers/formatAST.h b/contrib/clickhouse/src/Parsers/formatAST.h new file mode 100644 index 0000000000..dd72a59b4a --- /dev/null +++ b/contrib/clickhouse/src/Parsers/formatAST.h @@ -0,0 +1,48 @@ +#pragma once + +#include <Parsers/IAST.h> + + +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<DB::ASTPtr> +{ + template<typename ParseContext> + constexpr auto parse(ParseContext & context) + { + return context.begin(); + } + + template<typename FormatContext> + auto format(const DB::ASTPtr & ast, FormatContext & context) + { + return fmt::format_to(context.out(), "{}", DB::serializeAST(*ast)); + } +}; + |