NativeBlockInputStream.cpp 891 字节
Newer Older
A
Alexey Milovidov 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <DB/IO/ReadHelpers.h>
#include <DB/IO/VarInt.h>

#include <DB/DataStreams/NativeBlockInputStream.h>


namespace DB
{

Block NativeBlockInputStream::read()
{
	Block res;

	if (istr.eof())
		return res;
	
	/// Размеры
	size_t columns = 0;
	size_t rows = 0;
	readVarUInt(columns, istr);
	readVarUInt(rows, istr);

	for (size_t i = 0; i < columns; ++i)
	{
		ColumnWithNameAndType column;

		/// Имя
		readStringBinary(column.name, istr);

		/// Тип
		String type_name;
		readStringBinary(type_name, istr);
		column.type = data_type_factory.get(type_name);

		/// Данные
		column.column = column.type->createColumn();
		column.type->deserializeBinary(*column.column, istr, rows);

		if (column.column->size() != rows)
			throw Exception("Cannot read all data in NativeBlockInputStream.", ErrorCodes::CANNOT_READ_ALL_DATA);

		res.insert(column);
	}

	return res;
}

}