2013-11-08 17:43:03 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/copyData.h>
|
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <DataStreams/MaterializingBlockInputStream.h>
|
2017-07-25 21:07:05 +00:00
|
|
|
#include <Storages/StorageMaterializedView.h>
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-10-24 19:32:23 +00:00
|
|
|
class ReplicatedMergeTreeBlockOutputStream;
|
|
|
|
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2017-07-25 21:07:05 +00:00
|
|
|
/** Writes data to the specified table and to all dependent materialized views.
|
2013-11-08 17:43:03 +00:00
|
|
|
*/
|
2013-11-13 14:39:48 +00:00
|
|
|
class PushingToViewsBlockOutputStream : public IBlockOutputStream
|
2013-11-08 17:43:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-12-05 11:42:13 +00:00
|
|
|
PushingToViewsBlockOutputStream(const StoragePtr & storage_,
|
2017-12-22 19:20:18 +00:00
|
|
|
const Context & context_, const ASTPtr & query_ptr_, bool no_destination = false);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-06-18 16:32:37 +00:00
|
|
|
Block getHeader() const override;
|
2017-10-24 19:32:23 +00:00
|
|
|
void write(const Block & block) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-05-21 23:17:57 +00:00
|
|
|
void flush() override;
|
|
|
|
void writePrefix() override;
|
|
|
|
void writeSuffix() override;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
StoragePtr storage;
|
|
|
|
BlockOutputStreamPtr output;
|
2017-10-24 19:32:23 +00:00
|
|
|
ReplicatedMergeTreeBlockOutputStream * replicated_output = nullptr;
|
|
|
|
|
2017-09-04 17:49:39 +00:00
|
|
|
const Context & context;
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr query_ptr;
|
2017-10-24 19:32:23 +00:00
|
|
|
|
2017-11-05 17:48:50 +00:00
|
|
|
struct ViewInfo
|
|
|
|
{
|
|
|
|
ASTPtr query;
|
2019-12-05 11:42:13 +00:00
|
|
|
StorageID table_id;
|
2017-11-05 17:48:50 +00:00
|
|
|
BlockOutputStreamPtr out;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<ViewInfo> views;
|
2017-10-24 19:32:23 +00:00
|
|
|
std::unique_ptr<Context> views_context;
|
2018-09-25 05:58:23 +00:00
|
|
|
|
|
|
|
void process(const Block & block, size_t view_num);
|
2013-11-08 17:43:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|