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
|
|
|
|
2020-10-07 18:51:10 +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);
|
2021-05-15 08:09:17 +00:00
|
|
|
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)
|
|
|
|
{
|
2021-04-14 23:08:43 +00:00
|
|
|
if (types[i]->shouldAlignRightInPrettyFormats())
|
2020-04-24 11:06:41 +00:00
|
|
|
writeString(right_alignment, out);
|
|
|
|
else
|
2021-04-14 23:08:43 +00:00
|
|
|
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,
|
2020-10-06 12:47:52 +00:00
|
|
|
const RowOutputFormatParams & params,
|
2020-04-16 20:10:42 +00:00
|
|
|
const FormatSettings & settings)
|
|
|
|
{
|
2020-10-06 12:47:52 +00:00
|
|
|
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
|
|
|
}
|