Fixed integration tests

This commit is contained in:
Maksim Kita 2021-04-25 17:05:48 +03:00
parent 0c012d4288
commit 375b77dbcb
3 changed files with 39 additions and 3 deletions

View File

@ -21,6 +21,7 @@ namespace ErrorCodes
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
extern const int THERE_IS_NO_COLUMN; extern const int THERE_IS_NO_COLUMN;
extern const int CANNOT_DETACH_DICTIONARY_AS_TABLE; extern const int CANNOT_DETACH_DICTIONARY_AS_TABLE;
extern const int DICTIONARY_ALREADY_EXISTS;
} }
namespace namespace
@ -241,9 +242,27 @@ void registerStorageDictionary(StorageFactory & factory)
if (query.is_dictionary) if (query.is_dictionary)
{ {
auto dictionary_id = args.table_id;
auto & external_dictionaries_loader = local_context->getExternalDictionariesLoader();
/// A dictionary with the same full name could be defined in *.xml config files.
if (external_dictionaries_loader.getCurrentStatus(dictionary_id.getFullNameNotQuoted()) != ExternalLoader::Status::NOT_EXIST)
throw Exception(ErrorCodes::DICTIONARY_ALREADY_EXISTS,
"Dictionary {} already exists.", dictionary_id.getFullNameNotQuoted());
/// Create dictionary storage that owns underlying dictionary /// Create dictionary storage that owns underlying dictionary
auto abstract_dictionary_configuration = getDictionaryConfigurationFromAST(args.query, local_context, args.table_id.database_name); auto abstract_dictionary_configuration = getDictionaryConfigurationFromAST(args.query, local_context, dictionary_id.database_name);
return StorageDictionary::create(args.table_id, abstract_dictionary_configuration, local_context); auto result_storage = StorageDictionary::create(dictionary_id, abstract_dictionary_configuration, local_context);
bool lazy_load = local_context->getConfigRef().getBool("dictionaries_lazy_load", true);
if (!lazy_load)
{
/// load() is called here to force loading the dictionary, wait until the loading is finished,
/// and throw an exception if the loading is failed.
external_dictionaries_loader.load(result_storage->getStorageID().getInternalDictionaryName());
}
return result_storage;
} }
else else
{ {

View File

@ -205,7 +205,7 @@ StoragePtr StorageFactory::get(
assert(arguments.getContext() == arguments.getContext()->getGlobalContext()); assert(arguments.getContext() == arguments.getContext()->getGlobalContext());
auto res = storages.at(name).creator_fn(arguments); auto res = storages.at(name).creator_fn(arguments);
if (!empty_engine_args.empty()) //-v547 if (!empty_engine_args.empty()) //-V547
{ {
/// Storage creator modified empty arguments list, so we should modify the query /// Storage creator modified empty arguments list, so we should modify the query
assert(storage_def && storage_def->engine && !storage_def->engine->arguments); assert(storage_def && storage_def->engine && !storage_def->engine->arguments);

View File

@ -288,6 +288,23 @@ def test_clickhouse_remote(started_cluster):
time.sleep(0.5) time.sleep(0.5)
node3.query("detach dictionary if exists test.clickhouse_remote") node3.query("detach dictionary if exists test.clickhouse_remote")
with pytest.raises(QueryRuntimeException):
node3.query("""
CREATE DICTIONARY test.clickhouse_remote(
id UInt64,
SomeValue1 UInt8,
SomeValue2 String
)
PRIMARY KEY id
LAYOUT(FLAT())
SOURCE(CLICKHOUSE(HOST 'node4' PORT 9000 USER 'default' PASSWORD 'default' TABLE 'xml_dictionary_table' DB 'test'))
LIFETIME(MIN 1 MAX 10)
""")
node3.query("attach dictionary test.clickhouse_remote")
node3.query("drop dictionary test.clickhouse_remote")
node3.query(""" node3.query("""
CREATE DICTIONARY test.clickhouse_remote( CREATE DICTIONARY test.clickhouse_remote(
id UInt64, id UInt64,