1#pragma once
2
3#include <DataStreams/copyData.h>
4#include <DataStreams/IBlockOutputStream.h>
5#include <DataStreams/OneBlockInputStream.h>
6#include <DataStreams/MaterializingBlockInputStream.h>
7#include <Storages/StorageMaterializedView.h>
8
9namespace DB
10{
11
12class ReplicatedMergeTreeBlockOutputStream;
13
14
15/** Writes data to the specified table and to all dependent materialized views.
16 */
17class PushingToViewsBlockOutputStream : public IBlockOutputStream
18{
19public:
20 PushingToViewsBlockOutputStream(
21 const String & database, const String & table, const StoragePtr & storage_,
22 const Context & context_, const ASTPtr & query_ptr_, bool no_destination = false);
23
24 Block getHeader() const override;
25 void write(const Block & block) override;
26
27 void flush() override;
28 void writePrefix() override;
29 void writeSuffix() override;
30
31private:
32 StoragePtr storage;
33 BlockOutputStreamPtr output;
34 ReplicatedMergeTreeBlockOutputStream * replicated_output = nullptr;
35
36 const Context & context;
37 ASTPtr query_ptr;
38
39 struct ViewInfo
40 {
41 ASTPtr query;
42 String database;
43 String table;
44 BlockOutputStreamPtr out;
45 };
46
47 std::vector<ViewInfo> views;
48 std::unique_ptr<Context> views_context;
49
50 void process(const Block & block, size_t view_num);
51};
52
53
54}
55