Fix compile errors, added output format test

This commit is contained in:
DarkWanderer 2019-01-30 23:38:47 +03:00
parent bcac2722d1
commit c8cff57a62
5 changed files with 52 additions and 8 deletions

View File

@ -8,8 +8,8 @@
namespace DB namespace DB
{ {
BinaryRowInputStream::BinaryRowInputStream(ReadBuffer & istr_, const Block & header_) BinaryRowInputStream::BinaryRowInputStream(ReadBuffer & istr_, const Block & header_, bool with_names_, bool with_types_)
: istr(istr_), header(header_) : istr(istr_), header(header_), with_names(with_names_), with_types(with_types_)
{ {
} }
@ -27,6 +27,34 @@ bool BinaryRowInputStream::read(MutableColumns & columns, RowReadExtension &)
} }
void BinaryRowInputStream::readPrefix()
{
UInt64 columns;
String tmp;
if (with_names || with_types)
{
readVarUInt(columns, istr)
}
if (with_names)
{
for (size_t i = 0; i < columns; ++i)
{
readStringBinary(tmp, istr);
}
}
if (with_types)
{
for (size_t i = 0; i < columns; ++i)
{
readStringBinary(tmp, istr);
}
}
}
void registerInputFormatRowBinary(FormatFactory & factory) void registerInputFormatRowBinary(FormatFactory & factory)
{ {
factory.registerInputFormat("RowBinary", []( factory.registerInputFormat("RowBinary", [](
@ -37,7 +65,18 @@ void registerInputFormatRowBinary(FormatFactory & factory)
const FormatSettings & settings) const FormatSettings & settings)
{ {
return std::make_shared<BlockInputStreamFromRowInputStream>( return std::make_shared<BlockInputStreamFromRowInputStream>(
std::make_shared<BinaryRowInputStream>(buf, sample), std::make_shared<BinaryRowInputStream>(buf, sample, false, false),
sample, max_block_size, settings);
});
factory.registerInputFormat("RowBinaryWithNamesAndTypes", [](
WriteBuffer & buf,
const Block & sample,
const Context &,
const FormatSettings &)
{
return std::make_shared<BlockInputStreamFromRowInputStream>(
std::make_shared<BinaryRowInputStream>(buf, sample, true, true),
sample, max_block_size, settings); sample, max_block_size, settings);
}); });
} }

View File

@ -15,13 +15,16 @@ class ReadBuffer;
class BinaryRowInputStream : public IRowInputStream class BinaryRowInputStream : public IRowInputStream
{ {
public: public:
BinaryRowInputStream(ReadBuffer & istr_, const Block & header_); BinaryRowInputStream(ReadBuffer & istr_, const Block & sample_, bool with_names_, bool with_types_);
bool read(MutableColumns & columns, RowReadExtension &) override; bool read(MutableColumns & columns, RowReadExtension &) override;
void readPrefix() override;
private: private:
ReadBuffer & istr; ReadBuffer & istr;
Block header; Block header;
bool with_names;
bool with_types;
}; };
} }

View File

@ -20,14 +20,14 @@ void BinaryRowOutputStream::writePrefix()
if (with_names || with_types) if (with_names || with_types)
{ {
writeVarUInt(columns) writeVarUInt(columns, ostr)
} }
if (with_names) if (with_names)
{ {
for (size_t i = 0; i < columns; ++i) for (size_t i = 0; i < columns; ++i)
{ {
writeBinary(sample.safeGetByPosition(i).name, ostr); writeStringBinary(sample.safeGetByPosition(i).name, ostr);
} }
} }
@ -35,7 +35,7 @@ void BinaryRowOutputStream::writePrefix()
{ {
for (size_t i = 0; i < columns; ++i) for (size_t i = 0; i < columns; ++i)
{ {
writeBinary(sample.safeGetByPosition(i).type->getName(), ostr); writeStringBinary(sample.safeGetByPosition(i).type->getName(), ostr);
} }
} }
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <Formats/IRowOutputStream.h> #include <Formats/IRowOutputStream.h>
#include <Core/Block.h>
namespace DB namespace DB
@ -16,7 +17,7 @@ class WriteBuffer;
class BinaryRowOutputStream : public IRowOutputStream class BinaryRowOutputStream : public IRowOutputStream
{ {
public: public:
BinaryRowOutputStream(WriteBuffer & ostr_); BinaryRowOutputStream(WriteBuffer & ostr_, const Block & sample_, bool with_names_, bool with_types_);
void writeField(const IColumn & column, const IDataType & type, size_t row_num) override; void writeField(const IColumn & column, const IDataType & type, size_t row_num) override;
void writePrefix() override; void writePrefix() override;

View File

@ -1,5 +1,6 @@
SET output_format_write_statistics = 0; SET output_format_write_statistics = 0;
SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT RowBinary; SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT RowBinary;
SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT RowBinaryWithNamesAndTypes;
SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT TabSeparatedWithNamesAndTypes; SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT TabSeparatedWithNamesAndTypes;
SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT TabSeparatedRaw; SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT TabSeparatedRaw;
SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT CSV; SELECT number * 246 + 10 AS n, toDate('2000-01-01') + n AS d, range(n) AS arr, arrayStringConcat(arrayMap(x -> reinterpretAsString(x), arr)) AS s, (n, d) AS tuple FROM system.numbers LIMIT 2 FORMAT CSV;