aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Dictionaries/readInvalidateQuery.cpp
blob: 25e131c130be1a959c2d47d981370c5a32104061 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "readInvalidateQuery.h"
#include <QueryPipeline/QueryPipelineBuilder.h>
#include <Processors/Executors/PullingPipelineExecutor.h>
#include <IO/WriteBufferFromString.h>
#include <Formats/FormatSettings.h>


namespace DB
{

namespace ErrorCodes
{
    extern const int TOO_MANY_COLUMNS;
    extern const int TOO_MANY_ROWS;
    extern const int RECEIVED_EMPTY_DATA;
}

std::string readInvalidateQuery(QueryPipeline pipeline)
{
    PullingPipelineExecutor executor(pipeline);

    Block block;
    while (executor.pull(block))
        if (block)
            break;

    if (!block)
        throw Exception(ErrorCodes::RECEIVED_EMPTY_DATA, "Empty response");

    auto columns = block.columns();
    if (columns > 1)
        throw Exception(ErrorCodes::TOO_MANY_COLUMNS, "Expected single column in resultset, got {}", std::to_string(columns));

    auto rows = block.rows();
    if (rows == 0)
        throw Exception(ErrorCodes::RECEIVED_EMPTY_DATA, "Expected single row in resultset, got 0");
    if (rows > 1)
        throw Exception(ErrorCodes::TOO_MANY_ROWS, "Expected single row in resultset, got at least {}", rows);

    WriteBufferFromOwnString out;
    auto & column_type = block.getByPosition(0);
    column_type.type->getDefaultSerialization()->serializeTextQuoted(*column_type.column->convertToFullColumnIfConst(), 0, out, FormatSettings());

    while (executor.pull(block))
        if (block.rows() > 0)
            throw Exception(ErrorCodes::TOO_MANY_ROWS, "Expected single row in resultset, got at least {}", rows + 1);

    return out.str();
}

}