ClickHouse/dbms/include/DB/DataStreams/NativeBlockInputStream.h

99 lines
3.1 KiB
C
Raw Normal View History

2011-08-19 19:18:15 +00:00
#pragma once
2011-09-04 21:23:19 +00:00
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <DB/DataStreams/MarkInCompressedFile.h>
2011-08-19 19:18:15 +00:00
namespace DB
{
class CompressedReadBufferFromFile;
/** Формат Native может содержать отдельно расположенный индекс,
* который позволяет понять, где какой столбец расположен,
* и пропускать ненужные столбцы.
*/
/** Позиция одного кусочка одного столбца. */
struct IndexOfOneColumnForNativeFormat
{
String name;
String type;
MarkInCompressedFile location;
};
/** Индекс для блока данных. */
struct IndexOfBlockForNativeFormat
{
using Columns = std::vector<IndexOfOneColumnForNativeFormat>;
size_t num_columns;
size_t num_rows;
Columns columns;
};
/** Весь индекс. */
struct IndexForNativeFormat
{
using Blocks = std::vector<IndexOfBlockForNativeFormat>;
Blocks blocks;
IndexForNativeFormat() {}
IndexForNativeFormat(ReadBuffer & istr, const NameSet & required_columns)
{
read(istr, required_columns);
}
/// Прочитать индекс, только для нужных столбцов.
void read(ReadBuffer & istr, const NameSet & required_columns);
};
2011-08-19 19:18:15 +00:00
/** Десериализует поток блоков из родного бинарного формата (с именами и типами столбцов).
* Предназначено для взаимодействия между серверами.
*
* Также может использоваться для хранения данных на диске.
* В этом случае, может использовать индекс.
2011-08-19 19:18:15 +00:00
*/
2011-09-04 21:23:19 +00:00
class NativeBlockInputStream : public IProfilingBlockInputStream
2011-08-19 19:18:15 +00:00
{
public:
/** В случае указания ненулевой server_revision, может ожидаться и считываться дополнительная информация о блоке,
* в зависимости от поддерживаемой для указанной ревизии.
*
* index - не обязательный параметр. Если задан, то будут читаться только указанные в индексе кусочки столбцов.
*/
NativeBlockInputStream(
ReadBuffer & istr_, UInt64 server_revision_ = 0,
const IndexForNativeFormat * index_ = nullptr);
2011-08-19 19:18:15 +00:00
String getName() const override { return "Native"; }
String getID() const override
{
std::stringstream res;
res << this;
return res.str();
}
static void readData(const IDataType & type, IColumn & column, ReadBuffer & istr, size_t rows);
2012-10-20 02:10:47 +00:00
protected:
Block readImpl() override;
2012-10-20 02:10:47 +00:00
2011-08-19 19:18:15 +00:00
private:
ReadBuffer & istr;
UInt64 server_revision;
const IndexForNativeFormat * index;
IndexForNativeFormat::Blocks::const_iterator index_block_it;
IndexOfBlockForNativeFormat::Columns::const_iterator index_column_it;
/// Если задан индекс, то istr должен быть CompressedReadBufferFromFile.
CompressedReadBufferFromFile * istr_concrete;
2011-08-19 19:18:15 +00:00
};
}