aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Formats/Impl/JSONCompactColumnsBlockInputFormat.cpp
blob: 09df7beaa73555124694bb9ddae124c7cbefaee7 (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
55
56
57
58
59
60
61
#include <Processors/Formats/Impl/JSONCompactColumnsBlockInputFormat.h>
#include <IO/ReadHelpers.h>
#include <Formats/FormatFactory.h>
#include <Formats/EscapingRuleUtils.h>
#include <Formats/JSONUtils.h>

namespace DB
{

JSONCompactColumnsReader::JSONCompactColumnsReader(ReadBuffer & in_) : JSONColumnsReaderBase(in_)
{
}

void JSONCompactColumnsReader::readChunkStart()
{
    JSONUtils::skipArrayStart(*in);
}

std::optional<String> JSONCompactColumnsReader::readColumnStart()
{
    JSONUtils::skipArrayStart(*in);
    return std::nullopt;
}

bool JSONCompactColumnsReader::checkChunkEnd()
{
    return JSONUtils::checkAndSkipArrayEnd(*in);
}


void registerInputFormatJSONCompactColumns(FormatFactory & factory)
{
    factory.registerInputFormat(
        "JSONCompactColumns",
        [](ReadBuffer & buf,
           const Block &sample,
           const RowInputFormatParams &,
           const FormatSettings & settings)
        {
            return std::make_shared<JSONColumnsBlockInputFormatBase>(buf, sample, settings, std::make_unique<JSONCompactColumnsReader>(buf));
        }
    );
}

void registerJSONCompactColumnsSchemaReader(FormatFactory & factory)
{
    factory.registerSchemaReader(
        "JSONCompactColumns",
        [](ReadBuffer & buf, const FormatSettings & settings)
        {
            return std::make_shared<JSONColumnsSchemaReaderBase>(buf, settings, std::make_unique<JSONCompactColumnsReader>(buf));
        }
    );
    factory.registerAdditionalInfoForSchemaCacheGetter("JSONCompactColumns", [](const FormatSettings & settings)
    {
        auto result = getAdditionalFormatInfoForAllRowBasedFormats(settings) + getAdditionalFormatInfoByEscapingRule(settings, FormatSettings::EscapingRule::JSON);
        return result + fmt::format(", column_names_for_schema_inference={}", settings.column_names_for_schema_inference);
    });
}

}