1 | #pragma once |
2 | |
3 | #include <Core/Block.h> |
4 | #include <Processors/Formats/IRowInputFormat.h> |
5 | #include <IO/ReadBuffer.h> |
6 | #include <limits> |
7 | |
8 | |
9 | namespace DB |
10 | { |
11 | |
12 | class RowInputFormatWithDiagnosticInfo : public IRowInputFormat |
13 | { |
14 | public: |
15 | RowInputFormatWithDiagnosticInfo(const Block & , ReadBuffer & in_, const Params & params_); |
16 | |
17 | String getDiagnosticInfo() override; |
18 | |
19 | void resetParser() override; |
20 | |
21 | protected: |
22 | void updateDiagnosticInfo(); |
23 | bool deserializeFieldAndPrintDiagnosticInfo(const String & col_name, const DataTypePtr & type, IColumn & column, |
24 | WriteBuffer & out, size_t file_column); |
25 | String alignedName(const String & name, size_t max_length) const; |
26 | |
27 | virtual bool parseRowAndPrintDiagnosticInfo(MutableColumns & columns, WriteBuffer & out) = 0; |
28 | virtual void tryDeserializeFiled(const DataTypePtr & type, IColumn & column, size_t file_column, |
29 | ReadBuffer::Position & prev_pos, ReadBuffer::Position & curr_pos) = 0; |
30 | virtual bool isGarbageAfterField(size_t after_input_pos_idx, ReadBuffer::Position pos) = 0; |
31 | |
32 | /// For convenient diagnostics in case of an error. |
33 | size_t row_num = 0; |
34 | |
35 | private: |
36 | /// How many bytes were read, not counting those still in the buffer. |
37 | size_t bytes_read_at_start_of_buffer_on_current_row = 0; |
38 | size_t bytes_read_at_start_of_buffer_on_prev_row = 0; |
39 | |
40 | size_t offset_of_current_row = std::numeric_limits<size_t>::max(); |
41 | size_t offset_of_prev_row = std::numeric_limits<size_t>::max(); |
42 | |
43 | /// For alignment of diagnostic info. |
44 | size_t max_length_of_column_name = 0; |
45 | size_t max_length_of_data_type_name = 0; |
46 | }; |
47 | |
48 | } |
49 | |