2013-11-08 17:43:03 +00:00
|
|
|
#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>
|
2021-09-01 18:41:50 +00:00
|
|
|
#include <Processors/ISimpleTransform.h>
|
2021-01-05 17:10:12 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2021-09-01 18:41:50 +00:00
|
|
|
#include <Processors/Sinks/SinkToStorage.h>
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Common/Stopwatch.h>
|
2021-01-05 03:22:06 +00:00
|
|
|
|
2021-01-21 18:09:23 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
2021-06-29 09:25:34 +00:00
|
|
|
}
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-08-09 17:38:29 +00:00
|
|
|
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.
|
2021-08-23 10:46:52 +00:00
|
|
|
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-08-23 10:46:52 +00:00
|
|
|
|
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-28 11:32:27 +00:00
|
|
|
|
2021-06-29 09:25:34 +00:00
|
|
|
void setException(std::exception_ptr e)
|
2021-06-28 11:32:27 +00:00
|
|
|
{
|
|
|
|
exception = e;
|
2021-09-21 10:35:41 +00:00
|
|
|
runtime_stats->setStatus(QueryViewsLogElement::ViewStatus::EXCEPTION_WHILE_PROCESSING);
|
2021-06-28 11:32:27 +00:00
|
|
|
}
|
2021-06-18 13:44:08 +00:00
|
|
|
};
|
|
|
|
|
2017-07-25 21:07:05 +00:00
|
|
|
/** Writes data to the specified table and to all dependent materialized views.
|
2013-11-08 17:43:03 +00:00
|
|
|
*/
|
2021-09-22 10:57:00 +00:00
|
|
|
Chain buildPushingToViewsChain(
|
2021-09-01 18:41:50 +00:00
|
|
|
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.
|
2021-09-01 18:41:50 +00:00
|
|
|
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 = {});
|
2013-11-08 17:43:03 +00:00
|
|
|
|
|
|
|
}
|