2011-08-19 19:18:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
2021-10-08 17:21:19 +00:00
|
|
|
#include <Core/Block.h>
|
2011-08-19 19:18:15 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
class WriteBuffer;
|
|
|
|
class CompressedWriteBuffer;
|
2021-08-26 22:15:24 +00:00
|
|
|
struct IndexForNativeFormat;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
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.
|
2015-08-16 07:01:41 +00:00
|
|
|
*
|
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
|
|
|
*/
|
2021-10-08 17:21:19 +00:00
|
|
|
class NativeWriter
|
2011-08-19 19:18:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-08-16 20:27:35 +00:00
|
|
|
/** If non-zero client_revision is specified, additional block information can be written.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2021-10-08 17:21:19 +00:00
|
|
|
NativeWriter(
|
2018-12-19 16:47:30 +00:00
|
|
|
WriteBuffer & ostr_, UInt64 client_revision_, const Block & header_, bool remove_low_cardinality_ = false,
|
2021-08-26 22:15:24 +00:00
|
|
|
IndexForNativeFormat * index_ = nullptr, size_t initial_size_of_file_ = 0);
|
2011-08-19 19:18:15 +00:00
|
|
|
|
2021-10-08 17:21:19 +00:00
|
|
|
Block getHeader() const { return header; }
|
|
|
|
void write(const Block & block);
|
|
|
|
void flush();
|
2014-08-14 20:27:41 +00:00
|
|
|
|
2021-10-08 17:21:19 +00:00
|
|
|
static String getContentType() { return "application/octet-stream"; }
|
2015-10-29 20:38:37 +00:00
|
|
|
|
2011-08-19 19:18:15 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBuffer & ostr;
|
|
|
|
UInt64 client_revision;
|
2018-02-19 00:45:32 +00:00
|
|
|
Block header;
|
2021-08-26 22:15:24 +00:00
|
|
|
IndexForNativeFormat * index = nullptr;
|
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.
|
2017-04-01 07:20:54 +00:00
|
|
|
CompressedWriteBuffer * ostr_concrete = nullptr;
|
2018-12-19 17:54:46 +00:00
|
|
|
|
2018-12-19 16:47:30 +00:00
|
|
|
bool remove_low_cardinality;
|
2011-08-19 19:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|