Added more tests

This commit is contained in:
Maksim Kita 2021-06-18 23:59:35 +03:00
parent 7b03150b90
commit 3c9ae7b5ba
6 changed files with 100 additions and 14 deletions

View File

@ -210,7 +210,7 @@ void DatabaseAtomic::renameTable(ContextPtr local_context, const String & table_
std::unique_lock<std::mutex> other_db_lock;
if (inside_database)
db_lock = std::unique_lock{mutex};
else if (this < &other_db)
else if (this < &other_db)
{
db_lock = std::unique_lock{mutex};
other_db_lock = std::unique_lock{other_db.mutex};

View File

@ -215,29 +215,25 @@ LoadablesConfigurationPtr StorageDictionary::getConfiguration() const
void StorageDictionary::renameInMemory(const StorageID & new_table_id)
{
auto previous_table_id = getStorageID();
auto previous_dictionary_name = getStorageID().getInternalDictionaryName();
auto new_dictionary_name = new_table_id.getInternalDictionaryName();
auto old_table_id = getStorageID();
IStorage::renameInMemory(new_table_id);
dictionary_name = new_dictionary_name;
if (configuration)
{
configuration->setString("dictionary.database", new_table_id.database_name);
configuration->setString("dictionary.name", new_table_id.table_name);
const auto & external_dictionaries_loader = getContext()->getExternalDictionariesLoader();
external_dictionaries_loader.reloadConfig(previous_dictionary_name);
auto result = external_dictionaries_loader.getLoadResult(old_table_id.getInternalDictionaryName());
auto result = external_dictionaries_loader.getLoadResult(new_dictionary_name);
if (result.object)
{
const auto dictionary = std::static_pointer_cast<const IDictionary>(result.object);
dictionary->updateDictionaryName(new_table_id);
}
if (!result.object)
return;
const auto dictionary = std::static_pointer_cast<const IDictionary>(result.object);
dictionary->updateDictionaryName(new_table_id);
external_dictionaries_loader.reloadConfig(old_table_id.getInternalDictionaryName());
dictionary_name = new_table_id.getFullNameNotQuoted();
}
}

View File

@ -0,0 +1,4 @@
1 Table1
2 Table2
2 Table2
1 Table1

View File

@ -0,0 +1,34 @@
DROP TABLE IF EXISTS table_1;
CREATE TABLE table_1 (id UInt64, value String) ENGINE=TinyLog;
DROP TABLE IF EXISTS table_2;
CREATE TABLE table_2 (id UInt64, value String) ENGINE=TinyLog;
INSERT INTO table_1 VALUES (1, 'Table1');
INSERT INTO table_2 VALUES (2, 'Table2');
DROP DICTIONARY IF EXISTS dictionary_1;
CREATE DICTIONARY dictionary_1 (id UInt64, value String)
PRIMARY KEY id
LAYOUT(DIRECT())
SOURCE(CLICKHOUSE(TABLE 'table_1'));
DROP DICTIONARY IF EXISTS dictionary_2;
CREATE DICTIONARY dictionary_2 (id UInt64, value String)
PRIMARY KEY id
LAYOUT(DIRECT())
SOURCE(CLICKHOUSE(TABLE 'table_2'));
SELECT * FROM dictionary_1;
SELECT * FROM dictionary_2;
EXCHANGE DICTIONARIES dictionary_1 AND dictionary_2;
SELECT * FROM dictionary_1;
SELECT * FROM dictionary_2;
DROP DICTIONARY dictionary_1;
DROP DICTIONARY dictionary_2;
DROP TABLE table_1;
DROP TABLE table_2;

View File

@ -0,0 +1,2 @@
0 Value0
0 Value1

View File

@ -0,0 +1,50 @@
DROP DATABASE IF EXISTS 01915_db;
CREATE DATABASE 01915_db ENGINE=Atomic;
DROP TABLE IF EXISTS 01915_db.test_source_table_1;
CREATE TABLE 01915_db.test_source_table_1
(
id UInt64,
value String
) ENGINE=TinyLog;
INSERT INTO 01915_db.test_source_table_1 VALUES (0, 'Value0');
DROP DICTIONARY IF EXISTS 01915_db.test_dictionary;
CREATE OR REPLACE DICTIONARY 01915_db.test_dictionary
(
id UInt64,
value String
)
PRIMARY KEY id
LAYOUT(DIRECT())
SOURCE(CLICKHOUSE(DB '01915_db' TABLE 'test_source_table_1'));
SELECT * FROM 01915_db.test_dictionary;
DROP TABLE IF EXISTS 01915_db.test_source_table_2;
CREATE TABLE 01915_db.test_source_table_2
(
id UInt64,
value_1 String
) ENGINE=TinyLog;
INSERT INTO 01915_db.test_source_table_2 VALUES (0, 'Value1');
CREATE OR REPLACE DICTIONARY 01915_db.test_dictionary
(
id UInt64,
value_1 String
)
PRIMARY KEY id
LAYOUT(HASHED())
SOURCE(CLICKHOUSE(DB '01915_db' TABLE 'test_source_table_2'))
LIFETIME(0);
SELECT * FROM 01915_db.test_dictionary;
DROP DICTIONARY 01915_db.test_dictionary;
DROP TABLE 01915_db.test_source_table_1;
DROP TABLE 01915_db.test_source_table_2;
DROP DATABASE 01915_db;