ClickHouse/dbms/src/DataStreams/BlockOutputStreamFromRowOutputStream.cpp

45 lines
1.0 KiB
C++
Raw Normal View History

2011-10-24 12:10:59 +00:00
#include <DB/DataStreams/BlockOutputStreamFromRowOutputStream.h>
2013-05-22 14:57:43 +00:00
#include <DB/DataStreams/JSONRowOutputStream.h>
2011-10-24 12:10:59 +00:00
namespace DB
{
BlockOutputStreamFromRowOutputStream::BlockOutputStreamFromRowOutputStream(RowOutputStreamPtr row_output_)
2012-05-08 11:38:00 +00:00
: row_output(row_output_), first_row(true) {}
2011-10-24 12:10:59 +00:00
void BlockOutputStreamFromRowOutputStream::write(const Block & block)
{
size_t rows = block.rows();
size_t columns = block.columns();
for (size_t i = 0; i < rows; ++i)
{
2012-05-08 11:38:00 +00:00
if (!first_row)
2011-10-30 05:19:41 +00:00
row_output->writeRowBetweenDelimiter();
2012-05-08 11:38:00 +00:00
first_row = false;
2011-10-30 05:19:41 +00:00
2011-10-24 12:10:59 +00:00
row_output->writeRowStartDelimiter();
for (size_t j = 0; j < columns; ++j)
{
if (j != 0)
row_output->writeFieldDelimiter();
row_output->writeField((*block.getByPosition(j).column)[i]);
}
row_output->writeRowEndDelimiter();
}
}
2013-05-22 14:57:43 +00:00
void BlockOutputStreamFromRowOutputStream::setRowsBeforeLimit(size_t rows_before_limit)
{
if (JSONRowOutputStream * json_out = dynamic_cast<JSONRowOutputStream *>(&*row_output))
{
json_out->setRowsBeforeLimit(rows_before_limit);
}
}
2011-10-24 12:10:59 +00:00
}