2011-10-30 11:30:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
|
|
|
#include <DataStreams/BlockIO.h>
|
|
|
|
#include <Interpreters/IInterpreter.h>
|
2017-12-20 07:39:52 +00:00
|
|
|
#include <Parsers/ASTInsertQuery.h>
|
2020-06-16 12:48:10 +00:00
|
|
|
#include <Storages/StorageInMemoryMetadata.h>
|
2021-08-08 03:30:14 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
2011-10-30 11:30:52 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-08-27 03:00:12 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Interprets the INSERT query.
|
2011-10-30 11:30:52 +00:00
|
|
|
*/
|
2021-04-10 23:33:54 +00:00
|
|
|
class InterpreterInsertQuery : public IInterpreter, WithContext
|
2011-10-30 11:30:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-10-22 10:31:28 +00:00
|
|
|
InterpreterInsertQuery(
|
|
|
|
const ASTPtr & query_ptr_,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_,
|
2019-10-22 10:31:28 +00:00
|
|
|
bool allow_materialized_ = false,
|
|
|
|
bool no_squash_ = false,
|
|
|
|
bool no_destination_ = false);
|
2011-10-30 11:30:52 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Prepare a request for execution. Return block streams
|
|
|
|
* - the stream into which you can write data to execute the query, if INSERT;
|
|
|
|
* - the stream from which you can read the result of the query, if SELECT and similar;
|
|
|
|
* Or nothing if the request INSERT SELECT (self-sufficient query - does not accept the input data, does not return the result).
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
BlockIO execute() override;
|
2021-08-27 03:00:12 +00:00
|
|
|
Processors getSinks();
|
2020-03-02 20:23:58 +00:00
|
|
|
StorageID getDatabaseTable() const;
|
2018-07-16 14:52:02 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void extendQueryLogElemImpl(QueryLogElement & elem, const ASTPtr & ast, ContextPtr context_) const override;
|
2020-12-14 03:30:39 +00:00
|
|
|
|
2011-10-30 11:30:52 +00:00
|
|
|
private:
|
2020-01-24 16:20:36 +00:00
|
|
|
StoragePtr getTable(ASTInsertQuery & query);
|
2020-06-16 12:48:10 +00:00
|
|
|
Block getSampleBlock(const ASTInsertQuery & query, const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot) const;
|
2021-08-27 21:29:10 +00:00
|
|
|
std::pair<BlockIO, BlockOutputStreams> executeImpl(const StoragePtr & table, Block & sample_block);
|
2017-12-20 07:39:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ASTPtr query_ptr;
|
2019-08-29 15:36:07 +00:00
|
|
|
const bool allow_materialized;
|
|
|
|
const bool no_squash;
|
2019-10-22 10:31:28 +00:00
|
|
|
const bool no_destination;
|
2011-10-30 11:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|