2016-04-10 02:47:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
#include <string>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/IColumn.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <Formats/FormatSettings.h>
|
2018-07-16 01:02:46 +00:00
|
|
|
#include <Parsers/IdentifierQuotingStyle.h>
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2016-12-12 06:02:35 +00:00
|
|
|
struct DictionaryStructure;
|
2016-12-08 02:49:04 +00:00
|
|
|
class WriteBuffer;
|
2016-04-10 02:47:29 +00:00
|
|
|
|
|
|
|
|
2017-01-14 02:30:03 +00:00
|
|
|
/** Builds a query to load data from external database.
|
2016-04-10 02:47:29 +00:00
|
|
|
*/
|
|
|
|
struct ExternalQueryBuilder
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
const DictionaryStructure & dict_struct;
|
2018-10-15 14:49:23 +00:00
|
|
|
std::string db;
|
|
|
|
std::string schema;
|
2020-07-06 12:23:36 +00:00
|
|
|
std::string table;
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & where;
|
|
|
|
|
2018-07-16 01:02:46 +00:00
|
|
|
IdentifierQuotingStyle quoting_style;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
ExternalQueryBuilder(
|
2018-10-15 14:49:23 +00:00
|
|
|
const DictionaryStructure & dict_struct_,
|
|
|
|
const std::string & db_,
|
2020-07-06 12:23:36 +00:00
|
|
|
const std::string & schema_,
|
2018-10-15 14:49:23 +00:00
|
|
|
const std::string & table_,
|
|
|
|
const std::string & where_,
|
|
|
|
IdentifierQuotingStyle quoting_style_);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/** Generate a query to load all data. */
|
|
|
|
std::string composeLoadAllQuery() const;
|
|
|
|
|
2019-07-19 23:10:55 +00:00
|
|
|
/** Generate a query to load data after certain time point */
|
2018-12-10 15:25:45 +00:00
|
|
|
std::string composeUpdateQuery(const std::string & update_field, const std::string & time_point) const;
|
2018-01-15 12:44:39 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/** Generate a query to load data by set of UInt64 keys. */
|
|
|
|
std::string composeLoadIdsQuery(const std::vector<UInt64> & ids);
|
|
|
|
|
|
|
|
/** Generate a query to load data by set of composite keys.
|
2020-06-03 11:54:26 +00:00
|
|
|
* There are three methods of specification of composite keys in WHERE:
|
2017-04-01 07:20:54 +00:00
|
|
|
* 1. (x = c11 AND y = c12) OR (x = c21 AND y = c22) ...
|
|
|
|
* 2. (x, y) IN ((c11, c12), (c21, c22), ...)
|
2020-06-03 11:54:26 +00:00
|
|
|
* 3. (x = c1 AND (y, z) IN ((c2, c3), ...))
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
enum LoadKeysMethod
|
|
|
|
{
|
|
|
|
AND_OR_CHAIN,
|
|
|
|
IN_WITH_TUPLES,
|
2020-06-03 11:54:26 +00:00
|
|
|
CASSANDRA_SEPARATE_PARTITION_KEY,
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
2020-06-03 11:54:26 +00:00
|
|
|
std::string composeLoadKeysQuery(const Columns & key_columns, const std::vector<size_t> & requested_rows, LoadKeysMethod method, size_t partition_key_prefix = 0);
|
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:
|
2018-06-08 01:51:55 +00:00
|
|
|
const FormatSettings format_settings;
|
|
|
|
|
2020-05-26 19:21:18 +00:00
|
|
|
void composeLoadAllQuery(WriteBuffer & out) const;
|
|
|
|
|
2020-06-03 11:54:26 +00:00
|
|
|
/// In the following methods `beg` and `end` specifies which columns to write in expression
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Expression in form (x = c1 AND y = c2 ...)
|
2020-06-03 11:54:26 +00:00
|
|
|
void composeKeyCondition(const Columns & key_columns, const size_t row, WriteBuffer & out, size_t beg, size_t end) const;
|
|
|
|
|
|
|
|
/// Expression in form (x, y, ...) IN ((c1, c2, ...), ...)
|
|
|
|
void composeInWithTuples(const Columns & key_columns, const std::vector<size_t> & requested_rows, WriteBuffer & out, size_t beg, size_t end);
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Expression in form (x, y, ...)
|
2020-06-03 11:54:26 +00:00
|
|
|
void composeKeyTupleDefinition(WriteBuffer & out, size_t beg, size_t end) const;
|
2016-04-10 04:00:00 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Expression in form (c1, c2, ...)
|
2020-06-03 11:54:26 +00:00
|
|
|
void composeKeyTuple(const Columns & key_columns, const size_t row, WriteBuffer & out, size_t beg, size_t end) const;
|
2017-01-14 02:30:03 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Write string with specified quoting style.
|
|
|
|
void writeQuoted(const std::string & s, WriteBuffer & out) const;
|
2016-04-10 02:47:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|