2018-12-10 15:25:45 +00:00
|
|
|
#include "ExternalQueryBuilder.h"
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/WriteBufferFromString.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <boost/range/join.hpp>
|
|
|
|
#include <ext/range.h>
|
2018-11-28 11:37:12 +00:00
|
|
|
#include "DictionaryStructure.h"
|
2018-12-10 15:25:45 +00:00
|
|
|
#include "writeParenthesisedString.h"
|
2016-12-08 02:49:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int UNSUPPORTED_METHOD;
|
2020-08-31 22:52:12 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ExternalQueryBuilder::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_)
|
2020-07-06 12:23:36 +00:00
|
|
|
: dict_struct(dict_struct_), db(db_), schema(schema_), table(table_), where(where_), quoting_style(quoting_style_)
|
|
|
|
{}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
|
|
|
|
2017-01-14 02:30:03 +00:00
|
|
|
void ExternalQueryBuilder::writeQuoted(const std::string & s, WriteBuffer & out) const
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
switch (quoting_style)
|
|
|
|
{
|
2018-07-16 01:02:46 +00:00
|
|
|
case IdentifierQuotingStyle::None:
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(s, out);
|
|
|
|
break;
|
|
|
|
|
2018-07-16 01:02:46 +00:00
|
|
|
case IdentifierQuotingStyle::Backticks:
|
2017-04-01 07:20:54 +00:00
|
|
|
writeBackQuotedString(s, out);
|
|
|
|
break;
|
|
|
|
|
2018-07-16 01:02:46 +00:00
|
|
|
case IdentifierQuotingStyle::DoubleQuotes:
|
2017-04-01 07:20:54 +00:00
|
|
|
writeDoubleQuotedString(s, out);
|
|
|
|
break;
|
2019-06-21 05:22:04 +00:00
|
|
|
|
|
|
|
case IdentifierQuotingStyle::BackticksMySQL:
|
2019-06-24 14:51:37 +00:00
|
|
|
writeBackQuotedStringMySQL(s, out);
|
2019-06-21 05:22:04 +00:00
|
|
|
break;
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-01-14 02:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
std::string ExternalQueryBuilder::composeLoadAllQuery() const
|
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
WriteBufferFromOwnString out;
|
2020-05-26 19:21:18 +00:00
|
|
|
composeLoadAllQuery(out);
|
|
|
|
writeChar(';', out);
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalQueryBuilder::composeLoadAllQuery(WriteBuffer & out) const
|
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString("SELECT ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (dict_struct.id)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-10-04 00:22:00 +00:00
|
|
|
if (!dict_struct.id->expression.empty())
|
2017-07-31 21:39:24 +00:00
|
|
|
{
|
2017-10-04 00:22:00 +00:00
|
|
|
writeParenthesisedString(dict_struct.id->expression, out);
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" AS ", out);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
writeQuoted(dict_struct.id->name, out);
|
2017-07-31 21:39:24 +00:00
|
|
|
|
|
|
|
if (dict_struct.range_min && dict_struct.range_max)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(", ", out);
|
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
if (!dict_struct.range_min->expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-10-04 00:22:00 +00:00
|
|
|
writeParenthesisedString(dict_struct.range_min->expression, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(" AS ", out);
|
|
|
|
}
|
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
writeQuoted(dict_struct.range_min->name, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(", ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
if (!dict_struct.range_max->expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-10-04 00:22:00 +00:00
|
|
|
writeParenthesisedString(dict_struct.range_max->expression, out);
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" AS ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
writeQuoted(dict_struct.range_max->name, out);
|
2017-07-31 21:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dict_struct.key)
|
|
|
|
{
|
|
|
|
auto first = true;
|
|
|
|
for (const auto & key : *dict_struct.key)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!first)
|
|
|
|
writeString(", ", out);
|
|
|
|
|
|
|
|
first = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!key.expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
writeParenthesisedString(key.expression, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(" AS ", out);
|
|
|
|
}
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(key.name, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-07-31 21:39:24 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
for (const auto & attr : dict_struct.attributes)
|
|
|
|
{
|
|
|
|
writeString(", ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!attr.expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
writeParenthesisedString(attr.expression, out);
|
|
|
|
writeString(" AS ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(attr.name, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" FROM ", out);
|
|
|
|
if (!db.empty())
|
|
|
|
{
|
|
|
|
writeQuoted(db, out);
|
|
|
|
writeChar('.', out);
|
|
|
|
}
|
2018-10-15 14:49:23 +00:00
|
|
|
if (!schema.empty())
|
|
|
|
{
|
|
|
|
writeQuoted(schema, out);
|
|
|
|
writeChar('.', out);
|
|
|
|
}
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(table, out);
|
|
|
|
|
|
|
|
if (!where.empty())
|
|
|
|
{
|
|
|
|
writeString(" WHERE ", out);
|
|
|
|
writeString(where, out);
|
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-16 01:02:46 +00:00
|
|
|
std::string ExternalQueryBuilder::composeUpdateQuery(const std::string & update_field, const std::string & time_point) const
|
2018-01-15 12:44:39 +00:00
|
|
|
{
|
2020-05-26 19:21:18 +00:00
|
|
|
WriteBufferFromOwnString out;
|
|
|
|
composeLoadAllQuery(out);
|
2018-01-15 12:44:39 +00:00
|
|
|
|
2018-02-15 13:08:23 +00:00
|
|
|
if (!where.empty())
|
2020-05-26 19:21:18 +00:00
|
|
|
writeString(" AND ", out);
|
2018-02-15 13:08:23 +00:00
|
|
|
else
|
2020-05-26 19:21:18 +00:00
|
|
|
writeString(" WHERE ", out);
|
|
|
|
|
2020-07-10 13:03:36 +00:00
|
|
|
writeString(update_field, out);
|
2020-05-26 19:21:18 +00:00
|
|
|
writeString(" >= '", out);
|
|
|
|
writeString(time_point, out);
|
|
|
|
writeChar('\'', out);
|
2018-02-15 13:08:23 +00:00
|
|
|
|
2020-05-26 19:21:18 +00:00
|
|
|
writeChar(';', out);
|
|
|
|
return out.str();
|
2018-01-15 12:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-08 02:49:04 +00:00
|
|
|
std::string ExternalQueryBuilder::composeLoadIdsQuery(const std::vector<UInt64> & ids)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!dict_struct.id)
|
|
|
|
throw Exception{"Simple key required for method", ErrorCodes::UNSUPPORTED_METHOD};
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
WriteBufferFromOwnString out;
|
|
|
|
writeString("SELECT ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
if (!dict_struct.id->expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-10-04 00:22:00 +00:00
|
|
|
writeParenthesisedString(dict_struct.id->expression, out);
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" AS ", out);
|
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
writeQuoted(dict_struct.id->name, out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
for (const auto & attr : dict_struct.attributes)
|
|
|
|
{
|
|
|
|
writeString(", ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!attr.expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
writeParenthesisedString(attr.expression, out);
|
|
|
|
writeString(" AS ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(attr.name, out);
|
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" FROM ", out);
|
|
|
|
if (!db.empty())
|
|
|
|
{
|
|
|
|
writeQuoted(db, out);
|
|
|
|
writeChar('.', out);
|
|
|
|
}
|
2018-10-15 14:49:23 +00:00
|
|
|
if (!schema.empty())
|
|
|
|
{
|
|
|
|
writeQuoted(schema, out);
|
|
|
|
writeChar('.', out);
|
|
|
|
}
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(table, out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" WHERE ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!where.empty())
|
|
|
|
{
|
|
|
|
writeString(where, out);
|
|
|
|
writeString(" AND ", out);
|
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-10-04 00:22:00 +00:00
|
|
|
writeQuoted(dict_struct.id->name, out);
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" IN (", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
auto first = true;
|
|
|
|
for (const auto id : ids)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
writeString(", ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
first = false;
|
|
|
|
writeString(DB::toString(id), out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(");", out);
|
|
|
|
|
|
|
|
return out.str();
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-31 22:52:12 +00:00
|
|
|
std::string ExternalQueryBuilder::composeLoadKeysQuery(
|
|
|
|
const Columns & key_columns, const std::vector<size_t> & requested_rows, LoadKeysMethod method, size_t partition_key_prefix)
|
2016-12-08 02:49:04 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!dict_struct.key)
|
|
|
|
throw Exception{"Composite key required for method", ErrorCodes::UNSUPPORTED_METHOD};
|
|
|
|
|
2020-08-31 22:52:12 +00:00
|
|
|
if (key_columns.size() != dict_struct.key->size())
|
|
|
|
throw Exception{"The size of key_columns does not equal to the size of dictionary key", ErrorCodes::LOGICAL_ERROR};
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
WriteBufferFromOwnString out;
|
|
|
|
writeString("SELECT ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
auto first = true;
|
|
|
|
for (const auto & key_or_attribute : boost::join(*dict_struct.key, dict_struct.attributes))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!first)
|
|
|
|
writeString(", ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
first = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!key_or_attribute.expression.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-07-31 21:39:24 +00:00
|
|
|
writeParenthesisedString(key_or_attribute.expression, out);
|
|
|
|
writeString(" AS ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(key_or_attribute.name, out);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" FROM ", out);
|
|
|
|
if (!db.empty())
|
|
|
|
{
|
|
|
|
writeQuoted(db, out);
|
|
|
|
writeChar('.', out);
|
|
|
|
}
|
2018-10-15 14:49:23 +00:00
|
|
|
if (!schema.empty())
|
|
|
|
{
|
|
|
|
writeQuoted(schema, out);
|
|
|
|
writeChar('.', out);
|
|
|
|
}
|
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeQuoted(table, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(" WHERE ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (!where.empty())
|
|
|
|
{
|
2020-06-03 15:07:37 +00:00
|
|
|
if (method != CASSANDRA_SEPARATE_PARTITION_KEY)
|
|
|
|
writeString("(", out);
|
2017-07-31 21:39:24 +00:00
|
|
|
writeString(where, out);
|
2020-06-03 15:07:37 +00:00
|
|
|
if (method != CASSANDRA_SEPARATE_PARTITION_KEY)
|
|
|
|
writeString(") AND (", out);
|
|
|
|
else
|
|
|
|
writeString(" AND ", out);
|
2017-07-31 21:39:24 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
if (method == AND_OR_CHAIN)
|
|
|
|
{
|
|
|
|
first = true;
|
|
|
|
for (const auto row : requested_rows)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
writeString(" OR ", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-07-31 21:39:24 +00:00
|
|
|
first = false;
|
2020-06-03 11:54:26 +00:00
|
|
|
|
|
|
|
writeString("(", out);
|
|
|
|
composeKeyCondition(key_columns, row, out, 0, key_columns.size());
|
|
|
|
writeString(")", out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-07-31 21:39:24 +00:00
|
|
|
}
|
2020-06-03 11:54:26 +00:00
|
|
|
else if (method == IN_WITH_TUPLES)
|
2017-07-31 21:39:24 +00:00
|
|
|
{
|
2020-06-03 11:54:26 +00:00
|
|
|
composeInWithTuples(key_columns, requested_rows, out, 0, key_columns.size());
|
|
|
|
}
|
|
|
|
else /* if (method == CASSANDRA_SEPARATE_PARTITION_KEY) */
|
|
|
|
{
|
|
|
|
/// CQL does not allow using OR conditions
|
|
|
|
/// and does not allow using multi-column IN expressions with partition key columns.
|
|
|
|
/// So we have to use multiple queries with conditions like
|
|
|
|
/// (partition_key_1 = val1 AND partition_key_2 = val2 ...) AND (clustering_key_1, ...) IN ((val3, ...), ...)
|
|
|
|
/// for each partition key.
|
|
|
|
/// `partition_key_prefix` is a number of columns from partition key.
|
|
|
|
/// All `requested_rows` must have the same values of partition key.
|
|
|
|
composeKeyCondition(key_columns, requested_rows.at(0), out, 0, partition_key_prefix);
|
|
|
|
if (partition_key_prefix && partition_key_prefix < key_columns.size())
|
|
|
|
writeString(" AND ", out);
|
|
|
|
if (partition_key_prefix < key_columns.size())
|
|
|
|
composeInWithTuples(key_columns, requested_rows, out, partition_key_prefix, key_columns.size());
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 15:07:37 +00:00
|
|
|
if (!where.empty() && method != CASSANDRA_SEPARATE_PARTITION_KEY)
|
2017-07-31 21:39:24 +00:00
|
|
|
{
|
|
|
|
writeString(")", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeString(";", out);
|
|
|
|
|
|
|
|
return out.str();
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 11:54:26 +00:00
|
|
|
void ExternalQueryBuilder::composeKeyCondition(const Columns & key_columns, const size_t row, WriteBuffer & out,
|
|
|
|
size_t beg, size_t end) const
|
2016-12-08 02:49:04 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
auto first = true;
|
2020-06-03 11:54:26 +00:00
|
|
|
for (const auto i : ext::range(beg, end))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
writeString(" AND ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
first = false;
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const auto & key_description = (*dict_struct.key)[i];
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// key_i=value_i
|
2020-05-26 19:21:18 +00:00
|
|
|
writeQuoted(key_description.name, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString("=", out);
|
2021-03-13 18:05:18 +00:00
|
|
|
key_description.serialization->serializeTextQuoted(*key_columns[i], row, out, format_settings);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2020-06-03 11:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ExternalQueryBuilder::composeInWithTuples(const Columns & key_columns, const std::vector<size_t> & requested_rows,
|
|
|
|
WriteBuffer & out, size_t beg, size_t end)
|
|
|
|
{
|
|
|
|
composeKeyTupleDefinition(out, beg, end);
|
|
|
|
writeString(" IN (", out);
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
for (const auto row : requested_rows)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
writeString(", ", out);
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
composeKeyTuple(key_columns, row, out, beg, end);
|
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(")", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 11:54:26 +00:00
|
|
|
void ExternalQueryBuilder::composeKeyTupleDefinition(WriteBuffer & out, size_t beg, size_t end) const
|
2016-12-08 02:49:04 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!dict_struct.key)
|
|
|
|
throw Exception{"Composite key required for method", ErrorCodes::UNSUPPORTED_METHOD};
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2020-05-26 19:21:18 +00:00
|
|
|
writeChar('(', out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
auto first = true;
|
2020-06-03 11:54:26 +00:00
|
|
|
for (const auto i : ext::range(beg, end))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (!first)
|
2020-05-26 19:21:18 +00:00
|
|
|
writeString(", ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
first = false;
|
2020-06-03 11:54:26 +00:00
|
|
|
writeQuoted((*dict_struct.key)[i].name, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2020-05-26 19:21:18 +00:00
|
|
|
writeChar(')', out);
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-03 11:54:26 +00:00
|
|
|
void ExternalQueryBuilder::composeKeyTuple(const Columns & key_columns, const size_t row, WriteBuffer & out, size_t beg, size_t end) const
|
2016-12-08 02:49:04 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString("(", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
auto first = true;
|
2020-06-03 11:54:26 +00:00
|
|
|
for (const auto i : ext::range(beg, end))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
writeString(", ", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
first = false;
|
2021-03-13 18:05:18 +00:00
|
|
|
(*dict_struct.key)[i].serialization->serializeTextQuoted(*key_columns[i], row, out, format_settings);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(")", out);
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|