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>
|
2013-07-22 12:04:08 +00:00
|
|
|
#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_)
|
2012-12-29 15:41:17 +00:00
|
|
|
: 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
|
|
|
|
2012-12-29 15:41:17 +00:00
|
|
|
try
|
2010-05-21 19:52:50 +00:00
|
|
|
{
|
2012-12-29 15:41:17 +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
|
|
|
|
2013-01-07 00:57:43 +00:00
|
|
|
Row row;
|
|
|
|
bool has_row = row_input->read(row);
|
2010-05-24 16:52:58 +00:00
|
|
|
|
2013-01-07 00:57:43 +00:00
|
|
|
if (!has_row)
|
2013-07-22 13:21:16 +00:00
|
|
|
break;
|
2010-05-21 19:52:50 +00:00
|
|
|
|
2012-12-29 15:41:17 +00:00
|
|
|
if (!res)
|
|
|
|
res = sample.cloneEmpty();
|
2010-05-21 19:52:50 +00:00
|
|
|
|
2012-12-29 15:41:17 +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]);
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 03:20:51 +00:00
|
|
|
catch (Exception & e)
|
2012-12-29 15:41:17 +00:00
|
|
|
{
|
2013-10-26 03:20:51 +00:00
|
|
|
e.addMessage("(at row " + toString(total_rows + 1) + ")");
|
|
|
|
throw;
|
2010-05-21 19:52:50 +00:00
|
|
|
}
|
2015-10-04 03:17:36 +00:00
|
|
|
|
2013-08-02 14:26:04 +00:00
|
|
|
res.optimizeNestedArraysOffsets();
|
2015-10-04 03:17:36 +00:00
|
|
|
|
2010-05-21 19:52:50 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|