ClickHouse/src/Processors/Formats/Impl/RawBLOBRowInputFormat.cpp

56 lines
1.6 KiB
C++
Raw Normal View History

2020-09-28 00:11:19 +00:00
#include <Formats/FormatFactory.h>
#include <Processors/Formats/Impl/RawBLOBRowInputFormat.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeLowCardinality.h>
#include <IO/ReadHelpers.h>
namespace DB
{
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
RawBLOBRowInputFormat::RawBLOBRowInputFormat(const Block & header_, ReadBuffer & in_, Params params_)
: IRowInputFormat(header_, in_, std::move(params_))
{
if (header_.columns() > 1)
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"This input format is only suitable for tables with a single column of type String but the number of columns is {}",
header_.columns());
if (!isString(removeNullable(removeLowCardinality(header_.getByPosition(0).type))))
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"This input format is only suitable for tables with a single column of type String but the column type is {}",
header_.getByPosition(0).type->getName());
}
bool RawBLOBRowInputFormat::readRow(MutableColumns & columns, RowReadExtension &)
{
if (in->eof())
2020-09-28 00:11:19 +00:00
return false;
/// One excessive copy.
String blob;
readStringUntilEOF(blob, *in);
2020-09-28 00:11:19 +00:00
columns.at(0)->insertData(blob.data(), blob.size());
return false;
}
2021-10-11 16:11:50 +00:00
void registerInputFormatRawBLOB(FormatFactory & factory)
2020-09-28 00:11:19 +00:00
{
2021-10-11 16:11:50 +00:00
factory.registerInputFormat("RawBLOB", [](
2020-09-28 00:11:19 +00:00
ReadBuffer & buf,
const Block & sample,
const RowInputFormatParams & params,
const FormatSettings &)
{
return std::make_shared<RawBLOBRowInputFormat>(sample, buf, params);
});
}
}