2019-02-19 18:41:18 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <Columns/IColumn.h>
|
|
|
|
#include <DataTypes/IDataType.h>
|
|
|
|
#include <Processors/Formats/Impl/BinaryRowOutputFormat.h>
|
|
|
|
#include <Formats/FormatFactory.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-08-20 11:17:57 +00:00
|
|
|
BinaryRowOutputFormat::BinaryRowOutputFormat(WriteBuffer & out_, const Block & header, bool with_names_, bool with_types_, FormatFactory::WriteCallback callback)
|
|
|
|
: IRowOutputFormat(header, out_, callback), with_names(with_names_), with_types(with_types_)
|
2019-02-19 18:41:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinaryRowOutputFormat::writePrefix()
|
|
|
|
{
|
|
|
|
auto & header = getPort(PortKind::Main).getHeader();
|
|
|
|
size_t columns = header.columns();
|
|
|
|
|
|
|
|
if (with_names || with_types)
|
|
|
|
{
|
|
|
|
writeVarUInt(columns, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (with_names)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
{
|
|
|
|
writeStringBinary(header.safeGetByPosition(i).name, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (with_types)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
{
|
|
|
|
writeStringBinary(header.safeGetByPosition(i).type->getName(), out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BinaryRowOutputFormat::writeField(const IColumn & column, const IDataType & type, size_t row_num)
|
|
|
|
{
|
|
|
|
type.serializeBinary(column, row_num, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void registerOutputFormatProcessorRowBinary(FormatFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerOutputFormatProcessor("RowBinary", [](
|
|
|
|
WriteBuffer & buf,
|
|
|
|
const Block & sample,
|
|
|
|
const Context &,
|
2019-08-20 11:17:57 +00:00
|
|
|
FormatFactory::WriteCallback callback,
|
2019-02-19 18:41:18 +00:00
|
|
|
const FormatSettings &)
|
|
|
|
{
|
2019-08-20 11:17:57 +00:00
|
|
|
return std::make_shared<BinaryRowOutputFormat>(buf, sample, false, false, callback);
|
2019-02-19 18:41:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
factory.registerOutputFormatProcessor("RowBinaryWithNamesAndTypes", [](
|
|
|
|
WriteBuffer & buf,
|
|
|
|
const Block & sample,
|
|
|
|
const Context &,
|
2019-08-20 11:17:57 +00:00
|
|
|
FormatFactory::WriteCallback callback,
|
2019-02-19 18:41:18 +00:00
|
|
|
const FormatSettings &)
|
|
|
|
{
|
2019-08-20 11:17:57 +00:00
|
|
|
return std::make_shared<BinaryRowOutputFormat>(buf, sample, true, true, callback);
|
2019-02-19 18:41:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|