ClickHouse/src/Processors/Transforms/buildPushingToViewsChain.h

60 lines
1.9 KiB
C++
Raw Normal View History

#pragma once
2021-06-18 13:44:08 +00:00
#include <Interpreters/QueryViewsLog.h>
2021-01-05 03:22:06 +00:00
#include <Parsers/IAST_fwd.h>
2021-10-16 14:03:50 +00:00
#include <QueryPipeline/Chain.h>
#include <Processors/ISimpleTransform.h>
#include <Storages/IStorage.h>
#include <Processors/Sinks/SinkToStorage.h>
#include <Common/Stopwatch.h>
2021-01-05 03:22:06 +00:00
namespace Poco
{
class Logger;
2021-06-29 09:25:34 +00:00
}
namespace DB
{
struct ViewRuntimeData
2021-06-18 13:44:08 +00:00
{
2022-02-11 06:34:20 +00:00
/// A query we should run over inserted block before pushing into inner storage.
2021-06-21 15:58:15 +00:00
const ASTPtr query;
2021-09-22 10:57:00 +00:00
/// This structure is expected by inner storage. Will convert query result to it.
Block sample_block;
2021-09-22 10:57:00 +00:00
/// Inner storage id.
2021-06-18 13:44:08 +00:00
StorageID table_id;
2021-09-22 10:57:00 +00:00
/// In case of exception at any step (e.g. query execution or insertion into inner table)
/// exception is stored here (will be stored in query views log).
2021-06-18 13:44:08 +00:00
std::exception_ptr exception;
2021-09-22 10:57:00 +00:00
/// Info which is needed for query views log.
2021-09-21 10:35:41 +00:00
std::unique_ptr<QueryViewsLogElement::ViewRuntimeStats> runtime_stats;
2021-06-29 09:25:34 +00:00
void setException(std::exception_ptr e)
{
exception = e;
2021-09-21 10:35:41 +00:00
runtime_stats->setStatus(QueryViewsLogElement::ViewStatus::EXCEPTION_WHILE_PROCESSING);
}
2021-06-18 13:44:08 +00:00
};
/** Writes data to the specified table and to all dependent materialized views.
*/
2021-09-22 10:57:00 +00:00
Chain buildPushingToViewsChain(
const StoragePtr & storage,
const StorageMetadataPtr & metadata_snapshot,
ContextPtr context,
const ASTPtr & query_ptr,
2021-09-22 10:57:00 +00:00
/// It is true when we should not insert into table, but only to views.
/// Used e.g. for kafka. We should try to remove it somehow.
bool no_destination,
2021-09-22 10:57:00 +00:00
/// We could specify separate thread_status for each view.
/// Needed mainly to collect counters separately. Should be improved.
2021-09-21 10:35:41 +00:00
ThreadStatus * thread_status,
2021-09-22 10:57:00 +00:00
/// Counter to measure time spent separately per view. Should be improved.
2021-09-21 10:35:41 +00:00
std::atomic_uint64_t * elapsed_counter_ms,
2021-09-22 10:57:00 +00:00
/// LiveView executes query itself, it needs source block structure.
2021-09-21 10:35:41 +00:00
const Block & live_view_header = {});
}