| 1 | #pragma once | 
|---|
| 2 |  | 
|---|
| 3 | #include <Core/Block.h> | 
|---|
| 4 | #include <DataStreams/IBlockStream_fwd.h> | 
|---|
| 5 | #include <Storages/TableStructureLockHolder.h> | 
|---|
| 6 |  | 
|---|
| 7 | #include <boost/noncopyable.hpp> | 
|---|
| 8 |  | 
|---|
| 9 | #include <memory> | 
|---|
| 10 | #include <string> | 
|---|
| 11 | #include <vector> | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | namespace DB | 
|---|
| 15 | { | 
|---|
| 16 |  | 
|---|
| 17 | struct Progress; | 
|---|
| 18 |  | 
|---|
| 19 | /** Interface of stream for writing data (into table, filesystem, network, terminal, etc.) | 
|---|
| 20 | */ | 
|---|
| 21 | class IBlockOutputStream : private boost::noncopyable | 
|---|
| 22 | { | 
|---|
| 23 | public: | 
|---|
| 24 | IBlockOutputStream() {} | 
|---|
| 25 |  | 
|---|
| 26 | /** Get data structure of the stream in a form of "header" block (it is also called "sample block"). | 
|---|
| 27 | * Header block contains column names, data types, columns of size 0. Constant columns must have corresponding values. | 
|---|
| 28 | * You must pass blocks of exactly this structure to the 'write' method. | 
|---|
| 29 | */ | 
|---|
| 30 | virtual Block () const = 0; | 
|---|
| 31 |  | 
|---|
| 32 | /** Write block. | 
|---|
| 33 | */ | 
|---|
| 34 | virtual void write(const Block & block) = 0; | 
|---|
| 35 |  | 
|---|
| 36 | /** Write or do something before all data or after all data. | 
|---|
| 37 | */ | 
|---|
| 38 | virtual void writePrefix() {} | 
|---|
| 39 | virtual void writeSuffix() {} | 
|---|
| 40 |  | 
|---|
| 41 | /** Flush output buffers if any. | 
|---|
| 42 | */ | 
|---|
| 43 | virtual void flush() {} | 
|---|
| 44 |  | 
|---|
| 45 | /** Methods to set additional information for output in formats, that support it. | 
|---|
| 46 | */ | 
|---|
| 47 | virtual void setRowsBeforeLimit(size_t /*rows_before_limit*/) {} | 
|---|
| 48 | virtual void setTotals(const Block & /*totals*/) {} | 
|---|
| 49 | virtual void setExtremes(const Block & /*extremes*/) {} | 
|---|
| 50 |  | 
|---|
| 51 | /** Notify about progress. Method could be called from different threads. | 
|---|
| 52 | * Passed value are delta, that must be summarized. | 
|---|
| 53 | */ | 
|---|
| 54 | virtual void onProgress(const Progress & /*progress*/) {} | 
|---|
| 55 |  | 
|---|
| 56 | /** Content-Type to set when sending HTTP response. | 
|---|
| 57 | */ | 
|---|
| 58 | virtual std::string getContentType() const { return "text/plain; charset=UTF-8"; } | 
|---|
| 59 |  | 
|---|
| 60 | virtual ~IBlockOutputStream() {} | 
|---|
| 61 |  | 
|---|
| 62 | /** Don't let to alter table while instance of stream is alive. | 
|---|
| 63 | */ | 
|---|
| 64 | void addTableLock(const TableStructureReadLockHolder & lock) { table_locks.push_back(lock); } | 
|---|
| 65 |  | 
|---|
| 66 | private: | 
|---|
| 67 | std::vector<TableStructureReadLockHolder> table_locks; | 
|---|
| 68 | }; | 
|---|
| 69 |  | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|