ClickHouse/src/Interpreters/InterpreterInsertQuery.h

72 lines
2.4 KiB
C++
Raw Normal View History

2011-10-30 11:30:52 +00:00
#pragma once
#include <DataStreams/IBlockOutputStream.h>
#include <DataStreams/BlockIO.h>
#include <Interpreters/IInterpreter.h>
#include <Parsers/ASTInsertQuery.h>
#include <Storages/StorageInMemoryMetadata.h>
#include <IO/ReadBuffer.h>
2011-10-30 11:30:52 +00:00
namespace DB
{
struct ExceptionKeepingTransformRuntimeData;
using ExceptionKeepingTransformRuntimeDataPtr = std::shared_ptr<ExceptionKeepingTransformRuntimeData>;
2021-09-15 19:35:48 +00:00
class Chain;
2017-06-02 21:37:28 +00:00
/** Interprets the INSERT query.
2011-10-30 11:30:52 +00:00
*/
class InterpreterInsertQuery : public IInterpreter, WithContext
2011-10-30 11:30:52 +00:00
{
public:
InterpreterInsertQuery(
const ASTPtr & query_ptr_,
ContextPtr context_,
bool allow_materialized_ = false,
bool no_squash_ = false,
2021-09-15 19:35:48 +00:00
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).
*/
BlockIO execute() override;
2021-09-15 19:35:48 +00:00
Chain buildChain();
2012-03-19 12:57:56 +00:00
2021-09-09 16:10:53 +00:00
/// Returns only sinks, without input sources.
Processors getSinks();
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
2021-09-15 19:35:48 +00:00
Chain buildChain(
const StoragePtr & table,
const StorageMetadataPtr & metadata_snapshot,
const Names & columns,
ExceptionKeepingTransformRuntimeDataPtr runtime_data = nullptr);
void extendQueryLogElemImpl(QueryLogElement & elem, const ASTPtr & ast, ContextPtr context_) const override;
Block getSampleBlock(const ASTInsertQuery & query, const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot) const;
2021-09-15 19:35:48 +00:00
Block getSampleBlock(const Names & names, const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot) const;
2021-09-01 23:18:09 +00:00
StoragePtr getTable(ASTInsertQuery & query);
2020-12-14 03:30:39 +00:00
2011-10-30 11:30:52 +00:00
private:
std::pair<BlockIO, BlockOutputStreams> executeImpl(
const StoragePtr & table, const StorageMetadataPtr & metadata_snapshot, Block & sample_block);
ASTPtr query_ptr;
const bool allow_materialized;
const bool no_squash;
const bool no_destination;
2021-09-15 19:35:48 +00:00
Chain buildChainImpl(
const StoragePtr & table,
const StorageMetadataPtr & metadata_snapshot,
const Block & query_sample_block,
ExceptionKeepingTransformRuntimeDataPtr runtime_data = nullptr);
2011-10-30 11:30:52 +00:00
};
}