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);
|
2020-04-24 11:06:41 +00:00
|
|
|
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 central_alignment = ":-:|";
|
|
|
|
String right_alignment = "-:|";
|
2020-04-16 20:10:42 +00:00
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
{
|
2020-04-24 11:06:41 +00:00
|
|
|
if (isInteger(types[i]))
|
|
|
|
writeString(right_alignment, out);
|
|
|
|
else if (isString(types[i]))
|
|
|
|
writeString(left_alignment, out);
|
|
|
|
else
|
|
|
|
writeString(central_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
|
|
|
}
|
|
|
|
|
|
|
|
void MarkdownRowOutputFormat::writeField(const IColumn & column, const IDataType & type, size_t row_num)
|
|
|
|
{
|
|
|
|
type.serializeAsTextEscaped(column, row_num, out, format_settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|