Fix MySQLWire format (in case of multiple writes)

In case of multiple writes File() engine will set doNotWritePrefix(),
and this will avoid serializations initilization, move this to do this
always.

Fixes: #31004
This commit is contained in:
Azat Khuzhin 2021-11-20 15:23:37 +03:00
parent 4498aecaf6
commit 6aa94ae032
3 changed files with 15 additions and 7 deletions

View File

@ -24,6 +24,15 @@ MySQLOutputFormat::MySQLOutputFormat(WriteBuffer & out_, const Block & header_,
/// But it's also possible to specify MySQLWire as output format for clickhouse-client or clickhouse-local.
/// There is no `sequence_id` stored in `settings_.mysql_wire` in this case, so we create a dummy one.
sequence_id = settings_.mysql_wire.sequence_id ? settings_.mysql_wire.sequence_id : &dummy_sequence_id;
const auto & header = getPort(PortKind::Main).getHeader();
data_types = header.getDataTypes();
serializations.reserve(data_types.size());
for (const auto & type : data_types)
serializations.emplace_back(type->getDefaultSerialization());
packet_endpoint = MySQLProtocol::PacketEndpoint::create(out, *sequence_id);
}
void MySQLOutputFormat::setContext(ContextPtr context_)
@ -34,13 +43,6 @@ void MySQLOutputFormat::setContext(ContextPtr context_)
void MySQLOutputFormat::writePrefix()
{
const auto & header = getPort(PortKind::Main).getHeader();
data_types = header.getDataTypes();
serializations.reserve(data_types.size());
for (const auto & type : data_types)
serializations.emplace_back(type->getDefaultSerialization());
packet_endpoint = MySQLProtocol::PacketEndpoint::create(out, *sequence_id);
if (header.columns())
{

View File

@ -0,0 +1,6 @@
DROP TABLE IF EXISTS table_MySQLWire;
CREATE TABLE table_MySQLWire (x UInt64) ENGINE = File(MySQLWire);
INSERT INTO table_MySQLWire SELECT number FROM numbers(10);
-- regression for not initializing serializations
INSERT INTO table_MySQLWire SELECT number FROM numbers(10);
DROP TABLE table_MySQLWire;