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

@ -215,30 +215,26 @@ LoadablesConfigurationPtr StorageDictionary::getConfiguration() const
void StorageDictionary::renameInMemory(const StorageID & new_table_id) void StorageDictionary::renameInMemory(const StorageID & new_table_id)
{ {
auto previous_table_id = getStorageID(); auto old_table_id = getStorageID();
auto previous_dictionary_name = getStorageID().getInternalDictionaryName();
auto new_dictionary_name = new_table_id.getInternalDictionaryName();
IStorage::renameInMemory(new_table_id); IStorage::renameInMemory(new_table_id);
dictionary_name = new_dictionary_name;
if (configuration) if (configuration)
{ {
configuration->setString("dictionary.database", new_table_id.database_name); configuration->setString("dictionary.database", new_table_id.database_name);
configuration->setString("dictionary.name", new_table_id.table_name); configuration->setString("dictionary.name", new_table_id.table_name);
const auto & external_dictionaries_loader = getContext()->getExternalDictionariesLoader(); 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)
return;
if (result.object)
{
const auto dictionary = std::static_pointer_cast<const IDictionary>(result.object); const auto dictionary = std::static_pointer_cast<const IDictionary>(result.object);
dictionary->updateDictionaryName(new_table_id); dictionary->updateDictionaryName(new_table_id);
} }
external_dictionaries_loader.reloadConfig(old_table_id.getInternalDictionaryName());
dictionary_name = new_table_id.getFullNameNotQuoted();
}
} }
void registerStorageDictionary(StorageFactory & factory) void registerStorageDictionary(StorageFactory & factory)

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;