2010-03-04 19:20:28 +00:00
|
|
|
#include <DB/DataStreams/RowInputStreamFromBlockInputStream.h>
|
2010-05-24 17:55:57 +00:00
|
|
|
#include <DB/DataStreams/BlockInputStreamFromRowInputStream.h>
|
2010-03-04 19:20:28 +00:00
|
|
|
|
|
|
|
#include <DB/DataStreams/copyData.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-03-20 16:20:47 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
bool isAtomicSet(std::atomic<bool> * val)
|
|
|
|
{
|
|
|
|
return ((val != nullptr) && val->load(std::memory_order_seq_cst));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyData(IBlockInputStream & from, IBlockOutputStream & to, std::atomic<bool> * is_cancelled)
|
2010-03-04 19:20:28 +00:00
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
from.readPrefix();
|
|
|
|
to.writePrefix();
|
|
|
|
|
2010-03-04 19:20:28 +00:00
|
|
|
while (Block block = from.read())
|
2015-01-07 18:07:00 +00:00
|
|
|
{
|
2015-03-20 16:20:47 +00:00
|
|
|
if (isAtomicSet(is_cancelled))
|
2015-01-07 18:07:00 +00:00
|
|
|
break;
|
|
|
|
|
2010-03-04 19:20:28 +00:00
|
|
|
to.write(block);
|
2015-01-07 18:07:00 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 16:20:47 +00:00
|
|
|
if (isAtomicSet(is_cancelled))
|
2015-01-07 18:07:00 +00:00
|
|
|
return;
|
2011-10-31 06:37:12 +00:00
|
|
|
|
2013-09-01 04:55:41 +00:00
|
|
|
/// Для вывода дополнительной информации в некоторых форматах.
|
2013-09-08 08:27:06 +00:00
|
|
|
if (IProfilingBlockInputStream * input = dynamic_cast<IProfilingBlockInputStream *>(&from))
|
2013-09-01 04:55:41 +00:00
|
|
|
{
|
2013-05-31 17:34:30 +00:00
|
|
|
if (input->getInfo().hasAppliedLimit())
|
|
|
|
to.setRowsBeforeLimit(input->getInfo().getRowsBeforeLimit());
|
|
|
|
|
2013-09-01 04:55:41 +00:00
|
|
|
to.setTotals(input->getTotals());
|
2013-09-07 02:03:13 +00:00
|
|
|
to.setExtremes(input->getExtremes());
|
2013-09-01 04:55:41 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 16:20:47 +00:00
|
|
|
if (isAtomicSet(is_cancelled))
|
2015-01-07 18:07:00 +00:00
|
|
|
return;
|
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
from.readSuffix();
|
|
|
|
to.writeSuffix();
|
2010-03-04 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void copyData(IRowInputStream & from, IRowOutputStream & to)
|
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
from.readPrefix();
|
|
|
|
to.writePrefix();
|
|
|
|
|
|
|
|
bool first = true;
|
2010-03-04 19:20:28 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
if (first)
|
|
|
|
first = false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
from.readRowBetweenDelimiter();
|
|
|
|
to.writeRowBetweenDelimiter();
|
|
|
|
}
|
2015-01-07 18:07:00 +00:00
|
|
|
|
2013-01-07 00:57:43 +00:00
|
|
|
Row row;
|
|
|
|
bool has_rows = from.read(row);
|
|
|
|
if (!has_rows)
|
2010-03-04 19:20:28 +00:00
|
|
|
break;
|
|
|
|
to.write(row);
|
|
|
|
}
|
2011-10-31 06:37:12 +00:00
|
|
|
|
|
|
|
from.readSuffix();
|
|
|
|
to.writeSuffix();
|
2010-03-04 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|