2011-10-30 11:30:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-15 20:18:20 +00:00
|
|
|
#include <QueryPipeline/BlockIO.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#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>
|
2023-04-11 11:17:02 +00:00
|
|
|
#include <Common/ThreadStatus.h>
|
2011-10-30 11:30:52 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-09-15 19:35:48 +00:00
|
|
|
class Chain;
|
2021-09-21 10:35:41 +00:00
|
|
|
class ThreadStatus;
|
2021-09-15 19:35:48 +00:00
|
|
|
|
2022-09-21 18:37:40 +00:00
|
|
|
struct ThreadStatusesHolder;
|
|
|
|
using ThreadStatusesHolderPtr = std::shared_ptr<ThreadStatusesHolder>;
|
|
|
|
|
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,
|
2021-09-19 20:15:10 +00:00
|
|
|
bool no_destination_ = false,
|
|
|
|
bool async_insert_ = 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).
|
2012-03-11 08:52:56 +00:00
|
|
|
*/
|
2015-06-18 02:11:05 +00:00
|
|
|
BlockIO execute() override;
|
2021-09-09 16:10:53 +00:00
|
|
|
|
2020-03-02 20:23:58 +00:00
|
|
|
StorageID getDatabaseTable() const;
|
2018-07-16 14:52:02 +00:00
|
|
|
|
2023-09-14 19:31:12 +00:00
|
|
|
/// Return explicitly specified column names to insert.
|
|
|
|
/// It not explicit names were specified, return nullopt.
|
|
|
|
std::optional<Names> getInsertColumnNames() const;
|
|
|
|
|
2021-09-15 19:35:48 +00:00
|
|
|
Chain buildChain(
|
|
|
|
const StoragePtr & table,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
|
|
|
const Names & columns,
|
2022-09-21 18:37:40 +00:00
|
|
|
ThreadStatusesHolderPtr thread_status_holder = {},
|
2021-09-21 10:35:41 +00:00
|
|
|
std::atomic_uint64_t * elapsed_counter_ms = nullptr);
|
2021-09-15 19:35:48 +00:00
|
|
|
|
2021-12-28 14:47:19 +00:00
|
|
|
static void extendQueryLogElemImpl(QueryLogElement & elem, ContextPtr context_);
|
2023-02-01 02:11:54 +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
|
|
|
|
2021-09-17 12:59:40 +00:00
|
|
|
StoragePtr getTable(ASTInsertQuery & query);
|
|
|
|
Block getSampleBlock(const ASTInsertQuery & query, const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot) const;
|
2021-09-17 17:52:26 +00:00
|
|
|
|
2022-01-31 22:27:55 +00:00
|
|
|
bool supportsTransactions() const override { return true; }
|
|
|
|
|
2023-02-22 21:52:49 +00:00
|
|
|
void addBuffer(std::unique_ptr<ReadBuffer> buffer) { owned_buffers.push_back(std::move(buffer)); }
|
|
|
|
|
2021-09-17 17:52:26 +00:00
|
|
|
private:
|
2021-09-17 12:59:40 +00:00
|
|
|
Block getSampleBlock(const Names & names, const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot) const;
|
2017-12-20 07:39:52 +00:00
|
|
|
|
2011-10-30 11:30:52 +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;
|
2021-09-19 20:15:10 +00:00
|
|
|
const bool async_insert;
|
2021-09-15 19:35:48 +00:00
|
|
|
|
2023-02-22 21:52:49 +00:00
|
|
|
std::vector<std::unique_ptr<ReadBuffer>> owned_buffers;
|
|
|
|
|
2023-05-03 00:29:29 +00:00
|
|
|
Chain buildSink(
|
2021-09-15 19:35:48 +00:00
|
|
|
const StoragePtr & table,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
2022-09-21 18:37:40 +00:00
|
|
|
ThreadStatusesHolderPtr thread_status_holder,
|
2023-04-07 13:29:51 +00:00
|
|
|
ThreadGroupPtr running_group,
|
2021-09-21 10:35:41 +00:00
|
|
|
std::atomic_uint64_t * elapsed_counter_ms);
|
2023-05-03 00:29:29 +00:00
|
|
|
|
|
|
|
Chain buildPreSinkChain(
|
|
|
|
const Block & subsequent_header,
|
|
|
|
const StoragePtr & table,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
|
|
|
const Block & query_sample_block,
|
|
|
|
ThreadStatusesHolderPtr thread_status_holder);
|
2011-10-30 11:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|