Skip to content

Commit

Permalink
Merge pull request ClickHouse#63481 from ClickHouse/vdimir/fix_mysql_…
Browse files Browse the repository at this point in the history
…dictionary_source

Fix mysql dictionary source
  • Loading branch information
vdimir authored May 8, 2024
2 parents 834001d + b2377c3 commit 00de6f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Dictionaries/ExternalQueryBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
38 changes: 36 additions & 2 deletions tests/integration/test_dictionaries_mysql/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;")

Expand Down

0 comments on commit 00de6f2

Please sign in to comment.