ClickHouse/dbms/src/Dictionaries/readInvalidateQuery.cpp

47 lines
1.5 KiB
C++
Raw Normal View History

#include "readInvalidateQuery.h"
#include <DataStreams/IBlockInputStream.h>
#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
{
2017-05-22 16:46:14 +00:00
namespace ErrorCodes
{
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
}
std::string readInvalidateQuery(IBlockInputStream & block_input_stream)
2017-05-22 16:46:14 +00:00
{
block_input_stream.readPrefix();
2017-05-22 16:46:14 +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);
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);
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 22:34:52 +00:00
while ((block = block_input_stream.read()))
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
block_input_stream.readSuffix();
return out.str();
2017-05-22 16:46:14 +00:00
}
}