aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Sources/ThrowingExceptionSource.h
blob: 5abebd89d079f8a30b3cae26ede30e3b2baf41c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once
#include <Processors/ISource.h>


namespace DB
{

/// This source is throwing exception at the first attempt to read from it.
/// Can be used as a additional check that pipeline (or its part) is never executed.
class ThrowingExceptionSource : public ISource
{
public:

    using CallBack = std::function<Exception()>;

    explicit ThrowingExceptionSource(Block header, CallBack callback_)
        : ISource(std::move(header))
        , callback(std::move(callback_))
    {}

    String getName() const override { return "ThrowingExceptionSource"; }

protected:
    Chunk generate() override
    {
        throw callback();
    }

    CallBack callback;
};

}