1#include "readInvalidateQuery.h"
2#include <DataStreams/IBlockInputStream.h>
3#include <IO/WriteBufferFromString.h>
4#include <Formats/FormatSettings.h>
5
6
7namespace DB
8{
9
10namespace ErrorCodes
11{
12 extern const int TOO_MANY_COLUMNS;
13 extern const int TOO_MANY_ROWS;
14 extern const int RECEIVED_EMPTY_DATA;
15}
16
17std::string readInvalidateQuery(IBlockInputStream & block_input_stream)
18{
19 block_input_stream.readPrefix();
20
21 Block block = block_input_stream.read();
22 if (!block)
23 throw Exception("Empty response", ErrorCodes::RECEIVED_EMPTY_DATA);
24
25 auto columns = block.columns();
26 if (columns > 1)
27 throw Exception("Expected single column in resultset, got " + std::to_string(columns), ErrorCodes::TOO_MANY_COLUMNS);
28
29 auto rows = block.rows();
30 if (rows == 0)
31 throw Exception("Expected single row in resultset, got 0", ErrorCodes::RECEIVED_EMPTY_DATA);
32 if (rows > 1)
33 throw Exception("Expected single row in resultset, got at least " + std::to_string(rows), ErrorCodes::TOO_MANY_ROWS);
34
35 WriteBufferFromOwnString out;
36 auto & column_type = block.getByPosition(0);
37 column_type.type->serializeAsTextQuoted(*column_type.column->convertToFullColumnIfConst(), 0, out, FormatSettings());
38
39 while ((block = block_input_stream.read()))
40 if (block.rows() > 0)
41 throw Exception("Expected single row in resultset, got at least " + std::to_string(rows + 1), ErrorCodes::TOO_MANY_ROWS);
42
43 block_input_stream.readSuffix();
44 return out.str();
45}
46
47}
48