Fix referential dependencies when host & post in a clickHouse dictionary source are set by default.

This commit is contained in:
Vitaly Baranov 2022-12-05 19:37:41 +01:00
parent 0207637f6b
commit 5aaff60650
2 changed files with 14 additions and 6 deletions

View File

@ -623,20 +623,21 @@ getInfoIfClickHouseDictionarySource(DictionaryConfigurationPtr & config, Context
{
ClickHouseDictionarySourceInfo info;
String host = config->getString("dictionary.source.clickhouse.host", "");
UInt16 port = config->getUInt("dictionary.source.clickhouse.port", 0);
bool secure = config->getBool("dictionary.source.clickhouse.secure", false);
UInt16 default_port = secure ? global_context->getTCPPortSecure().value_or(0) : global_context->getTCPPort();
String host = config->getString("dictionary.source.clickhouse.host", "localhost");
UInt16 port = config->getUInt("dictionary.source.clickhouse.port", default_port);
String database = config->getString("dictionary.source.clickhouse.db", "");
String table = config->getString("dictionary.source.clickhouse.table", "");
bool secure = config->getBool("dictionary.source.clickhouse.secure", false);
if (host.empty() || port == 0 || table.empty())
if (table.empty())
return {};
info.table_name = {database, table};
try
{
UInt16 default_port = secure ? global_context->getTCPPortSecure().value_or(0) : global_context->getTCPPort();
if (isLocalAddress({host, port}, default_port))
info.is_local = true;
}

View File

@ -1182,6 +1182,7 @@ def test_tables_dependency():
t6 = random_table_names[5]
t7 = random_table_names[6]
t8 = random_table_names[7]
t9 = random_table_names[8]
# Create a materialized view and a dictionary with a local table as source.
instance.query(
@ -1210,12 +1211,17 @@ def test_tables_dependency():
f"CREATE TABLE {t8} AS {t2} ENGINE = Buffer({t2.split('.')[0]}, {t2.split('.')[1]}, 16, 10, 100, 10000, 1000000, 10000000, 100000000)"
)
instance.query(
f"CREATE DICTIONARY {t9} (x Int64, y String) PRIMARY KEY x SOURCE(CLICKHOUSE(TABLE '{t1.split('.')[1]}' DB '{t1.split('.')[0]}')) LAYOUT(FLAT()) LIFETIME(9)"
)
# Make backup.
backup_name = new_backup_name()
instance.query(f"BACKUP DATABASE test, DATABASE test2 TO {backup_name}")
# Drop everything in reversive order.
def drop():
instance.query(f"DROP DICTIONARY {t9}")
instance.query(f"DROP TABLE {t8} NO DELAY")
instance.query(f"DROP TABLE {t7} NO DELAY")
instance.query(f"DROP TABLE {t6} NO DELAY")
@ -1235,7 +1241,7 @@ def test_tables_dependency():
# Check everything is restored.
assert instance.query(
"SELECT concat(database, '.', name) AS c FROM system.tables WHERE database IN ['test', 'test2'] ORDER BY c"
) == TSV(sorted([t1, t2, t3, t4, t5, t6, t7, t8]))
) == TSV(sorted([t1, t2, t3, t4, t5, t6, t7, t8, t9]))
# Check logs.
instance.query("SYSTEM FLUSH LOGS")
@ -1251,6 +1257,7 @@ def test_tables_dependency():
f"Table {t6} has 1 dependencies: {t4} (level 2)",
f"Table {t7} has 1 dependencies: {t6} (level 3)",
f"Table {t8} has 1 dependencies: {t2} (level 1)",
f"Table {t9} has 1 dependencies: {t1} (level 1)",
]
for expect in expect_in_logs:
assert any(