ClickHouse/src/Processors/Formats/Impl/MarkdownRowOutputFormat.cpp

71 lines
2.0 KiB
C++
Raw Normal View History

2020-04-16 20:10:42 +00:00
#include <Processors/Formats/Impl/MarkdownRowOutputFormat.h>
#include <IO/WriteHelpers.h>
2020-04-24 11:06:41 +00:00
#include <DataTypes/IDataType.h>
2020-04-16 20:10:42 +00:00
namespace DB
{
2020-04-16 20:47:01 +00:00
MarkdownRowOutputFormat::MarkdownRowOutputFormat(WriteBuffer & out_, const Block & header_, const RowOutputFormatParams & params_, const FormatSettings & format_settings_)
: IRowOutputFormat(header_, out_, params_), format_settings(format_settings_) {}
2020-04-16 20:10:42 +00:00
void MarkdownRowOutputFormat::writePrefix()
{
2020-04-22 06:34:20 +00:00
const auto & header = getPort(PortKind::Main).getHeader();
2020-04-16 20:10:42 +00:00
size_t columns = header.columns();
2020-04-24 11:06:41 +00:00
writeCString("| ", out);
2020-04-16 20:10:42 +00:00
for (size_t i = 0; i < columns; ++i)
{
writeEscapedString(header.safeGetByPosition(i).name, out);
if (i == (columns - 1))
writeCString(" |", out);
else
writeCString(" | ", out);
2020-04-16 20:10:42 +00:00
}
writeCString("\n|", out);
2020-04-24 11:06:41 +00:00
String left_alignment = ":-|";
String right_alignment = "-:|";
2020-04-16 20:10:42 +00:00
for (size_t i = 0; i < columns; ++i)
{
if (types[i]->shouldAlignRightInPrettyFormats())
2020-04-24 11:06:41 +00:00
writeString(right_alignment, out);
else
writeString(left_alignment, out);
2020-04-16 20:10:42 +00:00
}
writeChar('\n', out);
}
void MarkdownRowOutputFormat::writeRowStartDelimiter()
{
2020-04-24 11:06:41 +00:00
writeCString("| ", out);
2020-04-16 20:10:42 +00:00
}
void MarkdownRowOutputFormat::writeFieldDelimiter()
{
2020-04-24 11:06:41 +00:00
writeCString(" | ", out);
2020-04-16 20:10:42 +00:00
}
void MarkdownRowOutputFormat::writeRowEndDelimiter()
{
2020-04-24 11:06:41 +00:00
writeCString(" |\n", out);
2020-04-16 20:10:42 +00:00
}
2021-03-09 14:46:52 +00:00
void MarkdownRowOutputFormat::writeField(const IColumn & column, const ISerialization & serialization, size_t row_num)
2020-04-16 20:10:42 +00:00
{
2021-03-09 14:46:52 +00:00
serialization.serializeTextEscaped(column, row_num, out, format_settings);
2020-04-16 20:10:42 +00:00
}
void registerOutputFormatProcessorMarkdown(FormatFactory & factory)
{
factory.registerOutputFormatProcessor("Markdown", [](
WriteBuffer & buf,
const Block & sample,
const RowOutputFormatParams & params,
2020-04-16 20:10:42 +00:00
const FormatSettings & settings)
{
return std::make_shared<MarkdownRowOutputFormat>(buf, sample, params, settings);
2020-04-16 20:10:42 +00:00
});
}
2020-04-16 20:11:52 +00:00
}