Merge pull request #56236 from evillique/fix-dictionaries

Fix ClickHouse-sourced dictionaries with an explicit query
This commit is contained in:
Nikolay Degterinsky 2023-11-06 22:37:27 +01:00 committed by GitHub
commit dd326729a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -396,18 +396,20 @@ std::string ExternalQueryBuilder::composeLoadKeysQuery(
}
else
{
writeString(query, out);
auto condition_position = query.find(CONDITION_PLACEHOLDER_TO_REPLACE_VALUE);
if (condition_position == std::string::npos)
{
writeString(" WHERE ", out);
writeString("SELECT * FROM (", out);
writeString(query, out);
writeString(") WHERE ", out);
composeKeysCondition(key_columns, requested_rows, method, partition_key_prefix, out);
writeString(";", out);
return out.str();
}
writeString(query, out);
WriteBufferFromOwnString condition_value_buffer;
composeKeysCondition(key_columns, requested_rows, method, partition_key_prefix, condition_value_buffer);
const auto & condition_value = condition_value_buffer.str();

View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Tags: zookeeper
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
${CLICKHOUSE_CLIENT} -n -q "
DROP DICTIONARY IF EXISTS 02907_dictionary;
DROP TABLE IF EXISTS 02907_table;
CREATE TABLE 02907_table (A String, B String) ENGINE=Memory AS SELECT 'a', 'b';
CREATE DICTIONARY 02907_dictionary(A String, B String) PRIMARY KEY A
SOURCE(CLICKHOUSE(QUERY \$\$ SELECT A, B FROM ${CLICKHOUSE_DATABASE}.02907_table ORDER BY A DESC LIMIT 1 BY A \$\$))
LAYOUT(complex_key_direct());
SELECT dictGet('02907_dictionary','B','a');
DROP DICTIONARY 02907_dictionary;
DROP TABLE 02907_table;"