Merge pull request #63508 from ClickHouse/backport/24.3/63481

Backport #63481 to 24.3: Fix mysql dictionary source
This commit is contained in:
robot-ch-test-poll3 2024-05-08 12:28:48 +02:00 committed by GitHub
commit ba9fe61a99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 3 deletions

View File

@ -401,7 +401,7 @@ std::string ExternalQueryBuilder::composeLoadKeysQuery(
{
writeString("SELECT * FROM (", out);
writeString(query, out);
writeString(") WHERE ", out);
writeString(") AS subquery WHERE ", out);
composeKeysCondition(key_columns, requested_rows, method, partition_key_prefix, out);
writeString(";", out);

View File

@ -76,7 +76,7 @@ def test_mysql_dictionaries_custom_query_full_load(started_cluster):
query = instance.query
query(
"""
f"""
CREATE DICTIONARY test_dictionary_custom_query
(
id UInt64,
@ -95,12 +95,46 @@ def test_mysql_dictionaries_custom_query_full_load(started_cluster):
"""
)
result = query("SELECT id, value_1, value_2 FROM test_dictionary_custom_query")
result = query(
"SELECT dictGetString('test_dictionary_custom_query', 'value_1', toUInt64(1))"
)
assert result == "Value_1\n"
result = query("SELECT id, value_1, value_2 FROM test_dictionary_custom_query")
assert result == "1\tValue_1\tValue_2\n"
query("DROP DICTIONARY test_dictionary_custom_query;")
query(
f"""
CREATE DICTIONARY test_cache_dictionary_custom_query
(
id1 UInt64,
id2 UInt64,
value_concat String
)
PRIMARY KEY id1, id2
LAYOUT(COMPLEX_KEY_CACHE(SIZE_IN_CELLS 10))
SOURCE(MYSQL(
HOST 'mysql80'
PORT 3306
USER 'root'
PASSWORD 'clickhouse'
QUERY 'SELECT id AS id1, id + 1 AS id2, CONCAT_WS(" ", "The", value_1) AS value_concat FROM test.test_table_1'))
LIFETIME(0)
"""
)
result = query(
"SELECT dictGetString('test_cache_dictionary_custom_query', 'value_concat', (1, 2))"
)
assert result == "The Value_1\n"
result = query("SELECT id1, value_concat FROM test_cache_dictionary_custom_query")
assert result == "1\tThe Value_1\n"
query("DROP DICTIONARY test_cache_dictionary_custom_query;")
execute_mysql_query(mysql_connection, "DROP TABLE test.test_table_1;")
execute_mysql_query(mysql_connection, "DROP TABLE test.test_table_2;")