| 1 | #pragma once |
| 2 | |
| 3 | #include <DataStreams/IBlockOutputStream.h> |
| 4 | #include <Core/Types.h> |
| 5 | #include <DataTypes/IDataType.h> |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | class WriteBuffer; |
| 11 | class CompressedWriteBuffer; |
| 12 | |
| 13 | |
| 14 | /** Serializes the stream of blocks in their native binary format (with names and column types). |
| 15 | * Designed for communication between servers. |
| 16 | * |
| 17 | * A stream can be specified to write the index. The index contains offsets to each part of each column. |
| 18 | * If an `append` is made to an existing file, and you need to write the index, then specify `initial_size_of_file`. |
| 19 | */ |
| 20 | class NativeBlockOutputStream : public IBlockOutputStream |
| 21 | { |
| 22 | public: |
| 23 | /** If non-zero client_revision is specified, additional block information can be written. |
| 24 | */ |
| 25 | NativeBlockOutputStream( |
| 26 | WriteBuffer & ostr_, UInt64 client_revision_, const Block & , bool remove_low_cardinality_ = false, |
| 27 | WriteBuffer * index_ostr_ = nullptr, size_t initial_size_of_file_ = 0); |
| 28 | |
| 29 | Block () const override { return header; } |
| 30 | void write(const Block & block) override; |
| 31 | void flush() override; |
| 32 | |
| 33 | static void writeData(const IDataType & type, const ColumnPtr & column, WriteBuffer & ostr, UInt64 offset, UInt64 limit); |
| 34 | |
| 35 | String getContentType() const override { return "application/octet-stream" ; } |
| 36 | |
| 37 | private: |
| 38 | WriteBuffer & ostr; |
| 39 | UInt64 client_revision; |
| 40 | Block ; |
| 41 | WriteBuffer * index_ostr; |
| 42 | size_t initial_size_of_file; /// The initial size of the data file, if `append` done. Used for the index. |
| 43 | /// If you need to write index, then `ostr` must be a CompressedWriteBuffer. |
| 44 | CompressedWriteBuffer * ostr_concrete = nullptr; |
| 45 | |
| 46 | bool remove_low_cardinality; |
| 47 | }; |
| 48 | |
| 49 | } |
| 50 | |