2016-04-10 02:47:29 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <DB/Columns/IColumn.h>
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
|
class DictionaryStructure;
|
|
|
|
|
class WriteBuffer;
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Генерирует запрос для загрузки данных из внешней БД.
|
|
|
|
|
*/
|
|
|
|
|
struct ExternalQueryBuilder
|
|
|
|
|
{
|
|
|
|
|
const DictionaryStructure & dict_struct;
|
|
|
|
|
const std::string & db;
|
|
|
|
|
const std::string & table;
|
|
|
|
|
const std::string & where;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExternalQueryBuilder(
|
|
|
|
|
const DictionaryStructure & dict_struct,
|
|
|
|
|
const std::string & db,
|
|
|
|
|
const std::string & table,
|
2016-12-08 02:49:04 +00:00
|
|
|
|
const std::string & where);
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
/** Получить запрос на загрузку всех данных. */
|
2016-12-08 02:49:04 +00:00
|
|
|
|
std::string composeLoadAllQuery() const;
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
/** Получить запрос на загрузку данных по множеству простых ключей. */
|
2016-12-08 02:49:04 +00:00
|
|
|
|
std::string composeLoadIdsQuery(const std::vector<UInt64> & ids);
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
|
|
|
|
/** Получить запрос на загрузку данных по множеству сложных ключей.
|
|
|
|
|
* Есть два метода их указания в секции WHERE:
|
|
|
|
|
* 1. (x = c11 AND y = c12) OR (x = c21 AND y = c22) ...
|
|
|
|
|
* 2. (x, y) IN ((c11, c12), (c21, c22), ...)
|
|
|
|
|
*/
|
|
|
|
|
enum LoadKeysMethod
|
|
|
|
|
{
|
|
|
|
|
AND_OR_CHAIN,
|
|
|
|
|
IN_WITH_TUPLES,
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-10 02:47:29 +00:00
|
|
|
|
std::string composeLoadKeysQuery(
|
2016-04-10 04:00:00 +00:00
|
|
|
|
const ConstColumnPlainPtrs & key_columns,
|
2016-12-08 02:49:04 +00:00
|
|
|
|
const std::vector<size_t> & requested_rows,
|
|
|
|
|
LoadKeysMethod method);
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
2016-04-10 02:47:29 +00:00
|
|
|
|
private:
|
2016-04-10 04:00:00 +00:00
|
|
|
|
/// Выражение вида (x = c1 AND y = c2 ...)
|
2016-12-08 02:49:04 +00:00
|
|
|
|
void composeKeyCondition(const ConstColumnPlainPtrs & key_columns, const size_t row, WriteBuffer & out) const;
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
|
|
|
|
/// Выражение вида (x, y, ...)
|
2016-12-08 02:49:04 +00:00
|
|
|
|
std::string composeKeyTupleDefinition() const;
|
2016-04-10 04:00:00 +00:00
|
|
|
|
|
|
|
|
|
/// Выражение вида (c1, c2, ...)
|
2016-12-08 02:49:04 +00:00
|
|
|
|
void composeKeyTuple(const ConstColumnPlainPtrs & key_columns, const size_t row, WriteBuffer & out) const;
|
2016-04-10 02:47:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|