2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
|
|
|
#include <DataStreams/copyData.h>
|
2010-03-04 19:20:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2015-03-20 16:20:47 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
bool isAtomicSet(std::atomic<bool> * val)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return ((val != nullptr) && val->load(std::memory_order_seq_cst));
|
2015-03-20 16:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-11 18:36:09 +00:00
|
|
|
template <typename TCancelCallback, typename TProgressCallback>
|
|
|
|
void copyDataImpl(IBlockInputStream & from, IBlockOutputStream & to, TCancelCallback && is_cancelled, TProgressCallback && progress)
|
2010-03-04 19:20:28 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
from.readPrefix();
|
|
|
|
to.writePrefix();
|
2011-10-31 06:37:12 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
while (Block block = from.read())
|
|
|
|
{
|
2017-11-09 18:06:36 +00:00
|
|
|
if (is_cancelled())
|
2017-04-01 07:20:54 +00:00
|
|
|
break;
|
2015-01-07 18:07:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
to.write(block);
|
2018-03-11 18:36:09 +00:00
|
|
|
progress(block);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-01-07 18:07:00 +00:00
|
|
|
|
2017-11-09 18:06:36 +00:00
|
|
|
if (is_cancelled())
|
2017-04-01 07:20:54 +00:00
|
|
|
return;
|
2011-10-31 06:37:12 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// For outputting additional information in some formats.
|
|
|
|
if (IProfilingBlockInputStream * input = dynamic_cast<IProfilingBlockInputStream *>(&from))
|
|
|
|
{
|
|
|
|
if (input->getProfileInfo().hasAppliedLimit())
|
|
|
|
to.setRowsBeforeLimit(input->getProfileInfo().getRowsBeforeLimit());
|
2013-05-31 17:34:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
to.setTotals(input->getTotals());
|
|
|
|
to.setExtremes(input->getExtremes());
|
|
|
|
}
|
2013-09-01 04:55:41 +00:00
|
|
|
|
2017-11-09 18:06:36 +00:00
|
|
|
if (is_cancelled())
|
2017-04-01 07:20:54 +00:00
|
|
|
return;
|
2015-01-07 18:07:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
from.readSuffix();
|
|
|
|
to.writeSuffix();
|
2010-03-04 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 18:06:36 +00:00
|
|
|
|
2018-03-11 18:36:09 +00:00
|
|
|
inline void doNothing(const Block &) {}
|
|
|
|
|
2017-11-09 18:06:36 +00:00
|
|
|
void copyData(IBlockInputStream & from, IBlockOutputStream & to, std::atomic<bool> * is_cancelled)
|
|
|
|
{
|
|
|
|
auto is_cancelled_pred = [is_cancelled] ()
|
|
|
|
{
|
|
|
|
return isAtomicSet(is_cancelled);
|
|
|
|
};
|
|
|
|
|
2018-03-11 18:36:09 +00:00
|
|
|
copyDataImpl(from, to, is_cancelled_pred, doNothing);
|
2017-11-09 18:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void copyData(IBlockInputStream & from, IBlockOutputStream & to, const std::function<bool()> & is_cancelled)
|
|
|
|
{
|
2018-03-11 18:36:09 +00:00
|
|
|
copyDataImpl(from, to, is_cancelled, doNothing);
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyData(IBlockInputStream & from, IBlockOutputStream & to, const std::function<bool()> & is_cancelled,
|
|
|
|
const std::function<void(const Block & block)> & progress)
|
|
|
|
{
|
|
|
|
copyDataImpl(from, to, is_cancelled, progress);
|
2017-11-09 18:06:36 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 19:20:28 +00:00
|
|
|
}
|