1 | #pragma once |
---|---|
2 | |
3 | #pragma once |
4 | |
5 | #include <Core/Block.h> |
6 | #include <Processors/Formats/IRowInputFormat.h> |
7 | #include <Formats/FormatSettings.h> |
8 | #include <Common/HashTable/HashMap.h> |
9 | |
10 | namespace DB |
11 | { |
12 | |
13 | class ReadBuffer; |
14 | |
15 | /** A stream for reading data in JSONCompactEachRow and JSONCompactEachRowWithNamesAndTypes formats |
16 | */ |
17 | class JSONCompactEachRowRowInputFormat : public IRowInputFormat |
18 | { |
19 | public: |
20 | JSONCompactEachRowRowInputFormat(ReadBuffer & in_, const Block & header_, Params params_, const FormatSettings & format_settings_, bool with_names_); |
21 | |
22 | String getName() const override { return "JSONCompactEachRowRowInputFormat"; } |
23 | |
24 | |
25 | void readPrefix() override; |
26 | bool readRow(MutableColumns & columns, RowReadExtension & ext) override; |
27 | bool allowSyncAfterError() const override { return true; } |
28 | void syncAfterError() override; |
29 | |
30 | |
31 | private: |
32 | void addInputColumn(const String & column_name); |
33 | void skipEndOfLine(); |
34 | void readField(size_t index, MutableColumns & columns); |
35 | |
36 | const FormatSettings format_settings; |
37 | |
38 | using IndexesMap = std::unordered_map<String, size_t>; |
39 | IndexesMap column_indexes_by_names; |
40 | |
41 | using OptionalIndexes = std::vector<std::optional<size_t>>; |
42 | OptionalIndexes column_indexes_for_input_fields; |
43 | |
44 | DataTypes data_types; |
45 | std::vector<UInt8> read_columns; |
46 | std::vector<size_t> not_seen_columns; |
47 | |
48 | /// This is for the correct exceptions in skipping unknown fields. |
49 | std::vector<String> names_of_columns; |
50 | |
51 | bool with_names; |
52 | }; |
53 | |
54 | } |
55 |