IBlockOutputStream.h 1.3 KB
Newer Older
1 2
#pragma once

3
#include <boost/noncopyable.hpp>
4
#include <DB/Storages/IStorage.h>
A
Alexey Milovidov 已提交
5 6 7 8 9


namespace DB
{

A
Alexey Milovidov 已提交
10 11
class Block;

12

A
Alexey Milovidov 已提交
13
/** Interface of stream for writing data (into table, filesystem, network, terminal, etc.)
A
Alexey Milovidov 已提交
14
  */
15
class IBlockOutputStream : private boost::noncopyable
A
Alexey Milovidov 已提交
16 17
{
public:
18
	IBlockOutputStream() {}
A
Alexey Milovidov 已提交
19

A
Alexey Milovidov 已提交
20
	/** Write block.
A
Alexey Milovidov 已提交
21 22 23
	  */
	virtual void write(const Block & block) = 0;

A
Alexey Milovidov 已提交
24
	/** Write or do something before all data or after all data.
A
Alexey Milovidov 已提交
25 26 27
	  */
	virtual void writePrefix() {}
	virtual void writeSuffix() {}
28

A
Alexey Milovidov 已提交
29
	/** Flush output buffers if any.
30 31
	  */
	virtual void flush() {}
32

A
Alexey Milovidov 已提交
33
	/** Methods to set additional information for output in formats, that support it.
34
	  */
35
	virtual void setRowsBeforeLimit(size_t rows_before_limit) {}
36
	virtual void setTotals(const Block & totals) {}
37
	virtual void setExtremes(const Block & extremes) {}
A
Alexey Milovidov 已提交
38

A
Alexey Milovidov 已提交
39
	/** Content-Type to set when sending HTTP response.
40 41 42
	  */
	virtual String getContentType() const { return "text/plain; charset=UTF-8"; }

A
Alexey Milovidov 已提交
43
	virtual ~IBlockOutputStream() {}
44

A
Alexey Milovidov 已提交
45
	/** Don't let to alter table while instance of stream is alive.
46 47
	  */
	void addTableLock(const IStorage::TableStructureReadLockPtr & lock) { table_locks.push_back(lock); }
48

49
protected:
50
	IStorage::TableStructureReadLocks table_locks;
A
Alexey Milovidov 已提交
51 52
};

53 54
using BlockOutputStreamPtr = std::shared_ptr<IBlockOutputStream>;

55
}