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
|
#include <Processors/Formats/Impl/OneFormat.h>
#include <Formats/FormatFactory.h>
#include <Columns/ColumnsNumber.h>
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
OneInputFormat::OneInputFormat(const Block & header, ReadBuffer & in_) : IInputFormat(header, &in_)
{
if (header.columns() != 1)
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"One input format is only suitable for tables with a single column of type UInt8 but the number of columns is {}",
header.columns());
if (!WhichDataType(header.getByPosition(0).type).isUInt8())
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"One input format is only suitable for tables with a single column of type String but the column type is {}",
header.getByPosition(0).type->getName());
}
Chunk OneInputFormat::generate()
{
if (done)
return {};
done = true;
auto column = ColumnUInt8::create();
column->insertDefault();
return Chunk(Columns{std::move(column)}, 1);
}
void registerInputFormatOne(FormatFactory & factory)
{
factory.registerInputFormat("One", [](
ReadBuffer & buf,
const Block & sample,
const RowInputFormatParams &,
const FormatSettings &)
{
return std::make_shared<OneInputFormat>(sample, buf);
});
}
void registerOneSchemaReader(FormatFactory & factory)
{
factory.registerExternalSchemaReader("One", [](const FormatSettings &)
{
return std::make_shared<OneSchemaReader>();
});
}
}
|