aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Formats/InputFormatErrorsLogger.h
blob: 4b3766f4d37a8892071d2deb9f97a7195bfffab8 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once

#include <IO/WriteBufferFromFile.h>
#include <Interpreters/Context.h>


namespace DB
{

class InputFormatErrorsLogger
{
public:
    struct ErrorEntry
    {
        time_t time;
        size_t offset;
        String reason;
        String raw_data;
    };

    InputFormatErrorsLogger(const ContextPtr & context);

    virtual ~InputFormatErrorsLogger();

    virtual void logError(ErrorEntry entry);
    void logErrorImpl(ErrorEntry entry);

private:
    Block header;

    String errors_file_path;
    std::shared_ptr<WriteBufferFromFile> write_buf;
    OutputFormatPtr writer;

    String database;
    String table;
};

using InputFormatErrorsLoggerPtr = std::shared_ptr<InputFormatErrorsLogger>;

class ParallelInputFormatErrorsLogger : public InputFormatErrorsLogger
{
public:
    ParallelInputFormatErrorsLogger(const ContextPtr & context) : InputFormatErrorsLogger(context) { }

    ~ParallelInputFormatErrorsLogger() override;

    void logError(ErrorEntry entry) override;

private:
    std::mutex write_mutex;
};

}