Merge pull request #10479 from Avogar/markdown_format

Markdown format
This commit is contained in:
alexey-milovidov 2020-04-26 03:25:48 +03:00 committed by GitHub
commit 8820b43606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 deletions

View File

@ -1,5 +1,6 @@
#include <Processors/Formats/Impl/MarkdownRowOutputFormat.h>
#include <IO/WriteHelpers.h>
#include <DataTypes/IDataType.h>
namespace DB
{
@ -12,34 +13,41 @@ void MarkdownRowOutputFormat::writePrefix()
const auto & header = getPort(PortKind::Main).getHeader();
size_t columns = header.columns();
writeChar('|', out);
writeCString("| ", out);
for (size_t i = 0; i < columns; ++i)
{
writeEscapedString(header.safeGetByPosition(i).name, out);
writeChar('|', out);
writeCString(" | ", out);
}
writeCString("\n|", out);
String format = ":-:|";
String left_alignment = ":-|";
String central_alignment = ":-:|";
String right_alignment = "-:|";
for (size_t i = 0; i < columns; ++i)
{
writeString(format, out);
if (isInteger(types[i]))
writeString(right_alignment, out);
else if (isString(types[i]))
writeString(left_alignment, out);
else
writeString(central_alignment, out);
}
writeChar('\n', out);
}
void MarkdownRowOutputFormat::writeRowStartDelimiter()
{
writeChar('|', out);
writeCString("| ", out);
}
void MarkdownRowOutputFormat::writeFieldDelimiter()
{
writeChar('|', out);
writeCString(" | ", out);
}
void MarkdownRowOutputFormat::writeRowEndDelimiter()
{
writeCString("|\n", out);
writeCString(" |\n", out);
}
void MarkdownRowOutputFormat::writeField(const IColumn & column, const IDataType & type, size_t row_num)

View File

@ -1,5 +1,5 @@
|id|name|array|
|:-:|:-:|:-:|
|1|name1|[1,2,3]|
|2|name2|[4,5,6]|
|3|name3|[7,8,9]|
| id | name | array |
|-:|:-|:-:|
| 1 | name1 | [1,2,3] |
| 2 | name2 | [4,5,6] |
| 3 | name3 | [7,8,9] |