ClickHouse/dbms/include/DB/DataStreams/BlockIO.h

67 lines
1.6 KiB
C++
Raw Normal View History

2012-03-11 08:55:04 +00:00
#pragma once
#include <DB/DataStreams/IBlockInputStream.h>
#include <DB/DataStreams/IBlockOutputStream.h>
namespace DB
{
class ProcessListEntry;
2012-03-11 08:55:04 +00:00
struct BlockIO
{
2016-11-30 17:31:05 +00:00
/** process_list_entry should be destroyed after in and after out,
* since in and out contain pointer to an object inside process_list_entry
* (MemoryTracker * current_memory_tracker),
2016-11-30 17:31:05 +00:00
* which could be used before destroying of in and out.
*/
std::shared_ptr<ProcessListEntry> process_list_entry;
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.
/// Callbacks for query logging could be set here.
std::function<void(IBlockInputStream *, IBlockOutputStream *)> finish_callback;
std::function<void()> exception_callback;
/// Вызывайте эти функции, если нужно логгировать запрос.
void onFinish()
{
if (finish_callback)
finish_callback(in.get(), out.get());
}
void onException()
{
if (exception_callback)
exception_callback();
}
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;
finish_callback = rhs.finish_callback;
exception_callback = rhs.exception_callback;
return *this;
}
~BlockIO();
2012-03-11 08:55:04 +00:00
};
}