ClickHouse/dbms/src/Dictionaries/readInvalidateQuery.cpp

48 lines
1.4 KiB
C++
Raw Normal View History

2017-05-22 16:46:14 +00:00
#include <Dictionaries/readInvalidateQuery.h>
#include <DataStreams/IProfilingBlockInputStream.h>
namespace DB
{
namespace ErrorCodes
{
2018-03-09 23:23:15 +00:00
extern const int TOO_MANY_COLUMNS;
extern const int TOO_MANY_ROWS;
2017-05-22 16:46:14 +00:00
extern const int RECEIVED_EMPTY_DATA;
}
std::string readInvalidateQuery(IProfilingBlockInputStream & block_input_stream)
2017-05-22 16:46:14 +00:00
{
block_input_stream.readPrefix();
2017-05-22 16:46:14 +00:00
std::string response;
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);
auto column = block.getByPosition(0).column;
response = column->getDataAt(0).toString();
2017-05-23 22:34:52 +00:00
while ((block = block_input_stream.read()))
2017-05-22 16:46:14 +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
}
block_input_stream.readSuffix();
2017-05-22 16:46:14 +00:00
return response;
}
}