added readInvalidateQuery

This commit is contained in:
Nikolai Kochetov 2017-05-22 19:46:14 +03:00
parent 86e63d2bba
commit db3fbd91b7
2 changed files with 69 additions and 0 deletions

View 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;
}
}

View 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);
}