ClickHouse/dbms/src/DataStreams/BlockInputStreamFromRowInputStream.cpp

51 lines
988 B
C++
Raw Normal View History

2010-05-21 19:52:50 +00:00
#include <DB/Core/Exception.h>
#include <DB/Core/ErrorCodes.h>
#include <DB/DataStreams/BlockInputStreamFromRowInputStream.h>
namespace DB
{
using Poco::SharedPtr;
BlockInputStreamFromRowInputStream::BlockInputStreamFromRowInputStream(
2011-10-24 12:10:59 +00:00
RowInputStreamPtr row_input_,
2010-05-21 19:52:50 +00:00
const Block & sample_,
size_t max_block_size_)
: row_input(row_input_), sample(sample_), max_block_size(max_block_size_), first_row(true)
2010-05-21 19:52:50 +00:00
{
}
2011-09-04 21:23:19 +00:00
Block BlockInputStreamFromRowInputStream::readImpl()
2010-05-24 16:52:58 +00:00
{
Block res;
2010-05-21 19:52:50 +00:00
for (size_t rows = 0; rows < max_block_size; ++rows)
{
2012-05-08 11:39:28 +00:00
if (!first_row)
2011-10-31 06:37:12 +00:00
row_input->readRowBetweenDelimiter();
2012-05-08 11:39:28 +00:00
first_row = false;
2011-10-31 06:37:12 +00:00
2011-10-24 12:10:59 +00:00
Row row = row_input->read();
2010-05-21 19:52:50 +00:00
if (row.empty())
2010-05-24 16:52:58 +00:00
return res;
if (!res)
2011-09-19 03:34:23 +00:00
res = sample.cloneEmpty();
2010-05-21 19:52:50 +00:00
if (row.size() != sample.columns())
2010-05-21 19:52:50 +00:00
throw Exception("Number of columns doesn't match", ErrorCodes::NUMBER_OF_COLUMNS_DOESNT_MATCH);
for (size_t i = 0; i < row.size(); ++i)
2010-05-21 19:52:50 +00:00
res.getByPosition(i).column->insert(row[i]);
}
2010-05-24 16:52:58 +00:00
2010-05-21 19:52:50 +00:00
return res;
}
}