2012-03-11 08:55:04 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/DataStreams/IBlockInputStream.h>
|
|
|
|
|
#include <DB/DataStreams/IBlockOutputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2015-06-21 06:06:04 +00:00
|
|
|
|
class ProcessListEntry;
|
|
|
|
|
|
2012-03-11 08:55:04 +00:00
|
|
|
|
struct BlockIO
|
|
|
|
|
{
|
2015-03-06 20:14:45 +00:00
|
|
|
|
/** process_list_entry должен уничтожаться позже, чем in и out,
|
|
|
|
|
* так как внутри in и out есть ссылка на объект внутри process_list_entry
|
|
|
|
|
* (MemoryTracker * current_memory_tracker),
|
|
|
|
|
* которая может использоваться до уничтожения in и out.
|
|
|
|
|
*/
|
2015-06-21 06:06:04 +00:00
|
|
|
|
std::shared_ptr<ProcessListEntry> process_list_entry;
|
2015-03-06 20:14:45 +00:00
|
|
|
|
|
2012-03-11 08:55:04 +00:00
|
|
|
|
BlockInputStreamPtr in;
|
|
|
|
|
BlockOutputStreamPtr out;
|
2012-03-19 12:57:56 +00:00
|
|
|
|
|
|
|
|
|
Block in_sample; /// Пример блока, который будет прочитан из in.
|
|
|
|
|
Block out_sample; /// Пример блока, которого нужно писать в out.
|
2013-09-03 20:21:28 +00:00
|
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
|
/// Callbacks for query logging could be set here.
|
|
|
|
|
std::function<void(IBlockInputStream *, IBlockOutputStream *)> finish_callback;
|
|
|
|
|
std::function<void()> exception_callback;
|
2015-06-29 21:35:35 +00:00
|
|
|
|
|
|
|
|
|
/// Вызывайте эти функции, если нужно логгировать запрос.
|
|
|
|
|
void onFinish()
|
|
|
|
|
{
|
2015-07-14 03:05:10 +00:00
|
|
|
|
if (finish_callback)
|
2016-12-06 20:55:13 +00:00
|
|
|
|
finish_callback(in.get(), out.get());
|
2015-06-29 21:35:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void onException()
|
|
|
|
|
{
|
|
|
|
|
if (exception_callback)
|
|
|
|
|
exception_callback();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-06 20:14:45 +00:00
|
|
|
|
BlockIO & operator= (const BlockIO & rhs)
|
|
|
|
|
{
|
|
|
|
|
/// Обеспечиваем правильный порядок уничтожения.
|
|
|
|
|
out = nullptr;
|
|
|
|
|
in = nullptr;
|
|
|
|
|
process_list_entry = nullptr;
|
|
|
|
|
|
|
|
|
|
process_list_entry = rhs.process_list_entry;
|
|
|
|
|
in = rhs.in;
|
|
|
|
|
out = rhs.out;
|
|
|
|
|
in_sample = rhs.in_sample;
|
|
|
|
|
out_sample = rhs.out_sample;
|
|
|
|
|
|
2015-06-29 21:35:35 +00:00
|
|
|
|
finish_callback = rhs.finish_callback;
|
|
|
|
|
exception_callback = rhs.exception_callback;
|
|
|
|
|
|
2015-03-06 20:14:45 +00:00
|
|
|
|
return *this;
|
|
|
|
|
}
|
2015-06-21 06:06:04 +00:00
|
|
|
|
|
|
|
|
|
~BlockIO();
|
2012-03-11 08:55:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|