ClickHouse/dbms/src/DataStreams/NativeBlockOutputStream.h

50 lines
1.7 KiB
C++
Raw Normal View History

2011-08-19 19:18:15 +00:00
#pragma once
#include <DataStreams/IBlockOutputStream.h>
#include <Core/Types.h>
#include <DataTypes/IDataType.h>
2011-08-19 19:18:15 +00:00
namespace DB
{
class WriteBuffer;
class CompressedWriteBuffer;
2017-05-13 22:19:04 +00:00
/** Serializes the stream of blocks in their native binary format (with names and column types).
* Designed for communication between servers.
*
2017-05-13 22:19:04 +00:00
* A stream can be specified to write the index. The index contains offsets to each part of each column.
* If an `append` is made to an existing file, and you need to write the index, then specify `initial_size_of_file`.
2011-08-19 19:18:15 +00:00
*/
class NativeBlockOutputStream : public IBlockOutputStream
{
public:
/** If non-zero client_revision is specified, additional block information can be written.
*/
NativeBlockOutputStream(
WriteBuffer & ostr_, UInt64 client_revision_, const Block & header_, bool remove_low_cardinality_ = false,
WriteBuffer * index_ostr_ = nullptr, size_t initial_size_of_file_ = 0);
2011-08-19 19:18:15 +00:00
Block getHeader() const override { return header; }
void write(const Block & block) override;
void flush() override;
static void writeData(const IDataType & type, const ColumnPtr & column, WriteBuffer & ostr, size_t offset, size_t limit);
String getContentType() const override { return "application/octet-stream"; }
2015-10-29 20:38:37 +00:00
2011-08-19 19:18:15 +00:00
private:
WriteBuffer & ostr;
UInt64 client_revision;
Block header;
WriteBuffer * index_ostr;
2017-05-13 22:19:04 +00:00
size_t initial_size_of_file; /// The initial size of the data file, if `append` done. Used for the index.
/// If you need to write index, then `ostr` must be a CompressedWriteBuffer.
CompressedWriteBuffer * ostr_concrete = nullptr;
bool remove_low_cardinality;
2011-08-19 19:18:15 +00:00
};
}