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
62
|
#include <Processors/Formats/Impl/JSONColumnsBlockInputFormat.h>
#include <IO/ReadHelpers.h>
#include <Formats/FormatFactory.h>
#include <Formats/EscapingRuleUtils.h>
#include <Formats/JSONUtils.h>
namespace DB
{
JSONColumnsReader::JSONColumnsReader(ReadBuffer & in_) : JSONColumnsReaderBase(in_)
{
}
void JSONColumnsReader::readChunkStart()
{
JSONUtils::skipObjectStart(*in);
}
std::optional<String> JSONColumnsReader::readColumnStart()
{
auto name = JSONUtils::readFieldName(*in);
JSONUtils::skipArrayStart(*in);
return name;
}
bool JSONColumnsReader::checkChunkEnd()
{
return JSONUtils::checkAndSkipObjectEnd(*in);
}
void registerInputFormatJSONColumns(FormatFactory & factory)
{
factory.registerInputFormat(
"JSONColumns",
[](ReadBuffer & buf,
const Block &sample,
const RowInputFormatParams &,
const FormatSettings & settings)
{
return std::make_shared<JSONColumnsBlockInputFormatBase>(buf, sample, settings, std::make_unique<JSONColumnsReader>(buf));
}
);
factory.markFormatSupportsSubsetOfColumns("JSONColumns");
}
void registerJSONColumnsSchemaReader(FormatFactory & factory)
{
factory.registerSchemaReader(
"JSONColumns",
[](ReadBuffer & buf, const FormatSettings & settings)
{
return std::make_shared<JSONColumnsSchemaReaderBase>(buf, settings, std::make_unique<JSONColumnsReader>(buf));
}
);
factory.registerAdditionalInfoForSchemaCacheGetter("JSONColumns", [](const FormatSettings & settings)
{
return getAdditionalFormatInfoForAllRowBasedFormats(settings) + getAdditionalFormatInfoByEscapingRule(settings, FormatSettings::EscapingRule::JSON);
});
}
}
|