mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-23 10:10:50 +00:00
added readInvalidateQuery
This commit is contained in:
parent
86e63d2bba
commit
db3fbd91b7
56
dbms/src/Dictionaries/readInvalidateQuery.cpp
Normal file
56
dbms/src/Dictionaries/readInvalidateQuery.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <Dictionaries/readInvalidateQuery.h>
|
||||
#include <DataStreams/IProfilingBlockInputStream.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int TOO_MUCH_COLUMNS;
|
||||
extern const int TOO_MUCH_ROWS;
|
||||
extern const int RECEIVED_EMPTY_DATA;
|
||||
}
|
||||
|
||||
std::string readInvalidateQuery(IProfilingBlockInputStream & blockInputStream)
|
||||
{
|
||||
blockInputStream.readPrefix();
|
||||
std::string response;
|
||||
|
||||
try
|
||||
{
|
||||
Block block = blockInputStream.read();
|
||||
if (!block)
|
||||
throw Exception("Empty response", ErrorCodes::RECEIVED_EMPTY_DATA);
|
||||
|
||||
auto columns = block.columns();
|
||||
if (columns > 1)
|
||||
throw Exception("Expected single column in resultset, got " + std::to_string(columns), ErrorCodes::TOO_MUCH_COLUMNS);
|
||||
|
||||
auto rows = block.rows();
|
||||
if (rows == 0)
|
||||
throw Exception("Expected single row in resultset, got 0", ErrorCodes::RECEIVED_EMPTY_DATA);
|
||||
if (rows > 1)
|
||||
throw Exception("Expected single row in resultset, got at least " + std::to_string(rows), ErrorCodes::TOO_MUCH_ROWS);
|
||||
|
||||
auto column = block.getByPosition(0).column;
|
||||
response = column->getDataAt(0).toString();
|
||||
|
||||
while (block = blockInputStream.read())
|
||||
{
|
||||
if (block.rows() > 0)
|
||||
throw Exception("Expected single row in resultset, got at least " + std::to_string(rows + 1), ErrorCodes::TOO_MUCH_ROWS);
|
||||
}
|
||||
}
|
||||
catch (Exception& exception)
|
||||
{
|
||||
blockInputStream.cancel();
|
||||
blockInputStream.readSuffix();
|
||||
throw;
|
||||
}
|
||||
|
||||
blockInputStream.readSuffix();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
13
dbms/src/Dictionaries/readInvalidateQuery.h
Normal file
13
dbms/src/Dictionaries/readInvalidateQuery.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class IProfilingBlockInputStream;
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
// Using in MySQLDictionarySource and ODBCDictionarySource after processing invalidate_query
|
||||
std::string readInvalidateQuery(IProfilingBlockInputStream & blockInputStream);
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user