ClickHouse/dbms/src/DataStreams/BlockInputStreamFromRowInputStream.cpp

62 lines
1.2 KiB
C++
Raw Normal View History

2015-10-05 01:35:28 +00:00
#include <DB/Common/Exception.h>
2010-05-21 19:52:50 +00:00
#include <DB/Core/ErrorCodes.h>
#include <DB/DataStreams/BlockInputStreamFromRowInputStream.h>
#include <DB/Columns/ColumnArray.h>
2010-05-21 19:52:50 +00:00
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_), total_rows(0)
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
try
2010-05-21 19:52:50 +00:00
{
for (size_t rows = 0; rows < max_block_size; ++rows, ++total_rows)
{
if (total_rows == 0)
row_input->readRowBetweenDelimiter();
2010-05-21 19:52:50 +00:00
Row row;
bool has_row = row_input->read(row);
2010-05-24 16:52:58 +00:00
if (!has_row)
break;
2010-05-21 19:52:50 +00:00
if (!res)
res = sample.cloneEmpty();
2010-05-21 19:52:50 +00:00
if (row.size() != sample.columns())
throw Exception("Number of columns doesn't match", ErrorCodes::NUMBER_OF_COLUMNS_DOESNT_MATCH);
for (size_t i = 0; i < row.size(); ++i)
res.getByPosition(i).column->insert(row[i]);
}
}
catch (Exception & e)
{
e.addMessage("(at row " + toString(total_rows + 1) + ")");
throw;
2010-05-21 19:52:50 +00:00
}
res.optimizeNestedArraysOffsets();
2010-05-21 19:52:50 +00:00
return res;
}
}