Add simpliest tests

This commit is contained in:
alesapin 2019-10-11 18:22:30 +03:00
parent dca0798d4d
commit 967fe64793
5 changed files with 152 additions and 5 deletions

View File

@ -115,8 +115,8 @@ ASTPtr parseCreateQueryFromMetadataFile(const String & filepath, Poco::Logger *
return nullptr;
}
ParserCreateQuery parser_table;
ASTPtr result = parseQuery(parser_table, definition, "in file " + filepath, 0);
ParserCreateQuery parser_create;
ASTPtr result = parseQuery(parser_create, definition, "in file " + filepath, 0);
return result;
}
@ -165,8 +165,10 @@ String getObjectDefinitionFromCreateQuery(const ASTPtr & query)
ASTPtr query_clone = query->clone();
auto & create = query_clone->as<ASTCreateQuery &>();
if (!create.is_dictionary)
create.attach = true;
/// We remove everything that is not needed for ATTACH from the query.
create.attach = true;
create.database.clear();
create.as_database.clear();
create.as_table.clear();

View File

@ -247,6 +247,12 @@ BlockIO InterpreterDropQuery::executeToDatabase(String & database_name, ASTDropQ
executeToTable(database_name, current_table_name, kind, false, false, false);
}
for (auto iterator = database->getDictionariesIterator(context); iterator->isValid(); iterator->next())
{
String current_dictionary = iterator->name();
executeToDictionary(database_name, current_dictionary, kind, false, false, false);
}
auto context_lock = context.getLock();
/// Someone could have time to delete the database before us.

View File

@ -41,7 +41,7 @@ NameSet getFilteredDictionaries(const ASTPtr & query, const Context & context, c
{
MutableColumnPtr column = ColumnString::create();
auto dicts_it = database->getDictionariesIterator(context);
while (dicts_it->isValid())
while (dicts_it && dicts_it->isValid())
{
column->insert(dicts_it->name());
dicts_it->next();
@ -137,7 +137,7 @@ void StorageSystemDictionaries::fillData(MutableColumns & res_columns, const Con
auto dictionaries_set = getFilteredDictionaries(query_info.query, context, database_ptr);
auto filter = [&dictionaries_set](const String & dict_name) { return dictionaries_set.count(dict_name); };
auto dictionaries_it = database_ptr->getDictionariesIterator(context, filter);
while (dictionaries_it->isValid())
while (dictionaries_it && dictionaries_it->isValid())
{
size_t i = 0;
res_columns[i++]->insert(database);

View File

@ -0,0 +1,25 @@
=DICTIONARY in Ordinary DB
CREATE DICTIONARY ordinary_db.dict1 (`key_column` UInt64 DEFAULT 0, `second_column` UInt8 DEFAULT 1, `third_column` String DEFAULT \'qqq\') PRIMARY KEY key_column SOURCE(CLICKHOUSE(HOST \'localhost\' PORT 9000 USER \'default\' TABLE \'table_for_dict\' PASSWORD \'\')) LIFETIME(MIN 1 MAX 10) LAYOUT(FLAT())
dict1
1
ordinary_db dict1
==DETACH DICTIONARY
0
==ATTACH DICTIONARY
dict1
1
ordinary_db dict1
==DROP DICTIONARY
0
=DICTIONARY in Memory DB
dict2
1
memory_db dict2
==DETACH DICTIONARY
0
==ATTACH DICTIONARY
dict2
1
memory_db dict2
==DROP DICTIONARY
0

View File

@ -0,0 +1,114 @@
SET send_logs_level = 'none';
DROP DATABASE IF EXISTS ordinary_db;
CREATE DATABASE ordinary_db ENGINE = Ordinary;
SELECT '=DICTIONARY in Ordinary DB';
DROP DICTIONARY IF EXISTS ordinary_db.dict1;
CREATE DICTIONARY ordinary_db.dict1
(
key_column UInt64 DEFAULT 0,
second_column UInt8 DEFAULT 1,
third_column String DEFAULT 'qqq'
)
PRIMARY KEY key_column
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD ''))
LIFETIME(MIN 1 MAX 10)
LAYOUT(FLAT());
SHOW CREATE DICTIONARY ordinary_db.dict1;
SHOW DICTIONARIES FROM ordinary_db LIKE 'dict1';
EXISTS DICTIONARY ordinary_db.dict1;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict1';
SELECT '==DETACH DICTIONARY';
DETACH DICTIONARY ordinary_db.dict1;
SHOW DICTIONARIES FROM ordinary_db LIKE 'dict1';
EXISTS DICTIONARY ordinary_db.dict1;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict1';
SELECT '==ATTACH DICTIONARY';
ATTACH DICTIONARY ordinary_db.dict1;
SHOW DICTIONARIES FROM ordinary_db LIKE 'dict1';
EXISTS DICTIONARY ordinary_db.dict1;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict1';
SELECT '==DROP DICTIONARY';
DROP DICTIONARY IF EXISTS ordinary_db.dict1;
SHOW DICTIONARIES FROM ordinary_db LIKE 'dict1';
EXISTS DICTIONARY ordinary_db.dict1;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict1';
DROP DATABASE IF EXISTS ordinary_db;
DROP DATABASE IF EXISTS memory_db;
CREATE DATABASE memory_db ENGINE = Memory;
SELECT '=DICTIONARY in Memory DB';
CREATE DICTIONARY memory_db.dict2
(
key_column UInt64 DEFAULT 0 INJECTIVE HIERARCHICAL,
second_column UInt8 DEFAULT 1 EXPRESSION rand() % 222,
third_column String DEFAULT 'qqq'
)
PRIMARY KEY key_column
SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'table_for_dict' PASSWORD ''))
LIFETIME(MIN 1 MAX 10)
LAYOUT(FLAT());
SHOW CREATE DICTIONARY memory_db.dict2; -- {serverError 500}
SHOW DICTIONARIES FROM memory_db LIKE 'dict2';
EXISTS DICTIONARY memory_db.dict2;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict2';
SELECT '==DETACH DICTIONARY';
DETACH DICTIONARY memory_db.dict2;
SHOW DICTIONARIES FROM memory_db LIKE 'dict2';
EXISTS DICTIONARY memory_db.dict2;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict2';
SELECT '==ATTACH DICTIONARY';
ATTACH DICTIONARY memory_db.dict2;
SHOW DICTIONARIES FROM memory_db LIKE 'dict2';
EXISTS DICTIONARY memory_db.dict2;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict2';
SELECT '==DROP DICTIONARY';
DROP DICTIONARY IF EXISTS memory_db.dict2;
SHOW DICTIONARIES FROM memory_db LIKE 'dict2';
EXISTS DICTIONARY memory_db.dict2;
SELECT database, name FROM system.dictionaries WHERE name LIKE 'dict2';
DROP DATABASE IF EXISTS memory_db;