1 | #pragma once |
2 | |
3 | #include <DataStreams/IBlockOutputStream.h> |
4 | #include <DataStreams/BlockIO.h> |
5 | #include <Interpreters/Context.h> |
6 | #include <Interpreters/IInterpreter.h> |
7 | #include <Parsers/ASTInsertQuery.h> |
8 | |
9 | namespace DB |
10 | { |
11 | |
12 | |
13 | /** Interprets the INSERT query. |
14 | */ |
15 | class InterpreterInsertQuery : public IInterpreter |
16 | { |
17 | public: |
18 | InterpreterInsertQuery( |
19 | const ASTPtr & query_ptr_, |
20 | const Context & context_, |
21 | bool allow_materialized_ = false, |
22 | bool no_squash_ = false, |
23 | bool no_destination_ = false); |
24 | |
25 | /** Prepare a request for execution. Return block streams |
26 | * - the stream into which you can write data to execute the query, if INSERT; |
27 | * - the stream from which you can read the result of the query, if SELECT and similar; |
28 | * Or nothing if the request INSERT SELECT (self-sufficient query - does not accept the input data, does not return the result). |
29 | */ |
30 | BlockIO execute() override; |
31 | |
32 | std::pair<String, String> getDatabaseTable() const; |
33 | |
34 | private: |
35 | StoragePtr getTable(const ASTInsertQuery & query); |
36 | Block getSampleBlock(const ASTInsertQuery & query, const StoragePtr & table); |
37 | void checkAccess(const ASTInsertQuery & query); |
38 | |
39 | ASTPtr query_ptr; |
40 | const Context & context; |
41 | const bool allow_materialized; |
42 | const bool no_squash; |
43 | const bool no_destination; |
44 | }; |
45 | |
46 | |
47 | } |
48 | |