2018-11-28 11:37:12 +00:00
|
|
|
#include "readInvalidateQuery.h"
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2019-03-04 18:21:07 +00:00
|
|
|
#include <IO/WriteBufferFromString.h>
|
2017-05-22 16:46:14 +00:00
|
|
|
|
2019-03-04 19:04:35 +00:00
|
|
|
|
2017-05-22 16:46:14 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2019-03-04 18:21:07 +00:00
|
|
|
|
2017-05-22 16:46:14 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2018-12-10 15:25:45 +00:00
|
|
|
extern const int TOO_MANY_COLUMNS;
|
|
|
|
extern const int TOO_MANY_ROWS;
|
|
|
|
extern const int RECEIVED_EMPTY_DATA;
|
2017-05-22 16:46:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
std::string readInvalidateQuery(IBlockInputStream & block_input_stream)
|
2017-05-22 16:46:14 +00:00
|
|
|
{
|
2017-05-23 16:36:07 +00:00
|
|
|
block_input_stream.readPrefix();
|
2017-05-22 16:46:14 +00:00
|
|
|
|
2017-05-23 16:36:07 +00:00
|
|
|
Block block = block_input_stream.read();
|
|
|
|
if (!block)
|
|
|
|
throw Exception("Empty response", ErrorCodes::RECEIVED_EMPTY_DATA);
|
|
|
|
|
|
|
|
auto columns = block.columns();
|
|
|
|
if (columns > 1)
|
2018-03-09 23:23:15 +00:00
|
|
|
throw Exception("Expected single column in resultset, got " + std::to_string(columns), ErrorCodes::TOO_MANY_COLUMNS);
|
2017-05-23 16:36:07 +00:00
|
|
|
|
|
|
|
auto rows = block.rows();
|
|
|
|
if (rows == 0)
|
|
|
|
throw Exception("Expected single row in resultset, got 0", ErrorCodes::RECEIVED_EMPTY_DATA);
|
|
|
|
if (rows > 1)
|
2018-03-09 23:23:15 +00:00
|
|
|
throw Exception("Expected single row in resultset, got at least " + std::to_string(rows), ErrorCodes::TOO_MANY_ROWS);
|
2017-05-23 16:36:07 +00:00
|
|
|
|
2019-03-04 18:21:07 +00:00
|
|
|
WriteBufferFromOwnString out;
|
|
|
|
auto & column_type = block.getByPosition(0);
|
2019-03-04 19:04:35 +00:00
|
|
|
column_type.type->serializeAsTextQuoted(*column_type.column->convertToFullColumnIfConst(), 0, out, FormatSettings());
|
2017-05-23 16:36:07 +00:00
|
|
|
|
2017-05-23 22:34:52 +00:00
|
|
|
while ((block = block_input_stream.read()))
|
2017-05-23 16:36:07 +00:00
|
|
|
if (block.rows() > 0)
|
2018-03-09 23:23:15 +00:00
|
|
|
throw Exception("Expected single row in resultset, got at least " + std::to_string(rows + 1), ErrorCodes::TOO_MANY_ROWS);
|
2017-05-22 16:46:14 +00:00
|
|
|
|
2017-05-23 16:36:07 +00:00
|
|
|
block_input_stream.readSuffix();
|
2019-03-04 18:21:07 +00:00
|
|
|
return out.str();
|
2017-05-22 16:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|