2011-08-19 19:18:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/MarkInCompressedFile.h>
|
2017-07-12 18:41:08 +00:00
|
|
|
#include <Common/PODArray.h>
|
2011-08-19 19:18:15 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
class CompressedReadBufferFromFile;
|
|
|
|
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** The Native format can contain a separately located index,
|
|
|
|
* which allows you to understand where what column is located,
|
|
|
|
* and skip unnecessary columns.
|
2015-08-16 07:01:41 +00:00
|
|
|
*/
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** The position of one piece of a single column. */
|
2015-08-16 07:01:41 +00:00
|
|
|
struct IndexOfOneColumnForNativeFormat
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
String name;
|
|
|
|
String type;
|
|
|
|
MarkInCompressedFile location;
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** The index for the data block. */
|
2015-08-16 07:01:41 +00:00
|
|
|
struct IndexOfBlockForNativeFormat
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using Columns = std::vector<IndexOfOneColumnForNativeFormat>;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t num_columns;
|
|
|
|
size_t num_rows;
|
|
|
|
Columns columns;
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** The whole index. */
|
2015-08-16 07:01:41 +00:00
|
|
|
struct IndexForNativeFormat
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using Blocks = std::vector<IndexOfBlockForNativeFormat>;
|
|
|
|
Blocks blocks;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
IndexForNativeFormat() {}
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
IndexForNativeFormat(ReadBuffer & istr, const NameSet & required_columns)
|
|
|
|
{
|
|
|
|
read(istr, required_columns);
|
|
|
|
}
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// Read the index, only for the required columns.
|
2017-04-01 07:20:54 +00:00
|
|
|
void read(ReadBuffer & istr, const NameSet & required_columns);
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** Deserializes the stream of blocks from the 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
|
|
|
* Can also be used to store data on disk.
|
|
|
|
* In this case, can use the index.
|
2011-08-19 19:18:15 +00:00
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class NativeBlockInputStream : public IBlockInputStream
|
2011-08-19 19:18:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-02-18 02:46:39 +00:00
|
|
|
/// If a non-zero server_revision is specified, additional block information may be expected and read.
|
|
|
|
NativeBlockInputStream(ReadBuffer & istr_, UInt64 server_revision_);
|
|
|
|
|
|
|
|
/// For cases when data structure (header) is known in advance.
|
|
|
|
/// NOTE We may use header for data validation and/or type conversions. It is not implemented.
|
2019-09-12 11:33:46 +00:00
|
|
|
NativeBlockInputStream(ReadBuffer & istr_, const Block & header_, UInt64 server_revision_);
|
2018-02-18 02:46:39 +00:00
|
|
|
|
|
|
|
/// For cases when we have an index. It allows to skip columns. Only columns specified in the index will be read.
|
|
|
|
NativeBlockInputStream(ReadBuffer & istr_, UInt64 server_revision_,
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_block_it_,
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_block_end_);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
String getName() const override { return "Native"; }
|
|
|
|
|
2017-07-12 18:41:08 +00:00
|
|
|
static void readData(const IDataType & type, IColumn & column, ReadBuffer & istr, size_t rows, double avg_value_size_hint);
|
2015-04-16 10:48:35 +00:00
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override;
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2019-11-26 23:46:19 +00:00
|
|
|
void resetParser();
|
|
|
|
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override;
|
2012-10-20 02:10:47 +00:00
|
|
|
|
2011-08-19 19:18:15 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBuffer & istr;
|
2018-02-18 02:46:39 +00:00
|
|
|
Block header;
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt64 server_revision;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2018-02-18 02:46:39 +00:00
|
|
|
bool use_index = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_block_it;
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_block_end;
|
|
|
|
IndexOfBlockForNativeFormat::Columns::const_iterator index_column_it;
|
2018-12-19 17:54:46 +00:00
|
|
|
|
2018-06-04 15:45:08 +00:00
|
|
|
/// If an index is specified, then `istr` must be CompressedReadBufferFromFile. Unused otherwise.
|
|
|
|
CompressedReadBufferFromFile * istr_concrete = nullptr;
|
2017-07-12 18:41:08 +00:00
|
|
|
|
|
|
|
PODArray<double> avg_value_size_hints;
|
|
|
|
|
|
|
|
void updateAvgValueSizeHints(const Block & block);
|
2011-08-19 19:18:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|