Fixed tests

This commit is contained in:
Maksim Kita 2021-10-14 22:12:06 +03:00
parent c1f04452de
commit 83879415b4
7 changed files with 78 additions and 22 deletions

View File

@ -40,6 +40,20 @@ struct QualifiedTableName
return hash_state.get64();
}
std::vector<std::string> getParts() const {
if (database.empty())
return {table};
else
return {database, table};
}
std::string getFullName() const {
if (database.empty())
return table;
else
return database + '.' + table;
}
/// NOTE: It's different from compound identifier parsing and does not support escaping and dots in name.
/// Usually it's better to use ParserIdentifier instead,
/// but we parse DDL dictionary name (and similar things) this way for historical reasons.

View File

@ -143,21 +143,12 @@ private:
{
if (auto * identifier = child->children[i]->as<ASTIdentifier>())
{
/// Identifier already qualified
if (identifier->compound())
continue;
auto storage_id = context->getExternalDictionariesLoader().getStorageID(identifier->name(), context);
if (!storage_id.database_name.empty())
{
std::vector<std::string> name_parts = {storage_id.database_name, storage_id.table_name};
child->children[i] = std::make_shared<ASTIdentifier>(std::move(name_parts));
}
else
{
std::vector<std::string> name_parts = {storage_id.table_name};
child->children[i] = std::make_shared<ASTIdentifier>(std::move(name_parts));
}
auto qualified_dictionary_name = context->getExternalDictionariesLoader().qualifyDictionaryNameWithDatabase(identifier->name(), context);
child->children[i] = std::make_shared<ASTIdentifier>(qualified_dictionary_name.getParts());
}
else if (auto * literal = child->children[i]->as<ASTLiteral>())
{
@ -167,7 +158,8 @@ private:
continue;
auto dictionary_name = literal_value.get<String>();
literal_value = context->getExternalDictionariesLoader().getStorageID(dictionary_name, context).getFullTableName();
auto qualified_dictionary_name = context->getExternalDictionariesLoader().qualifyDictionaryNameWithDatabase(dictionary_name, context);
literal_value = qualified_dictionary_name.getFullName();
}
}
else if (is_operator_in && i == 1)

View File

@ -87,19 +87,26 @@ DictionaryStructure ExternalDictionariesLoader::getDictionaryStructure(const std
return ExternalDictionariesLoader::getDictionaryStructure(*load_result.config);
}
StorageID ExternalDictionariesLoader::getStorageID(const std::string & dictionary_name, ContextPtr context) const
QualifiedTableName ExternalDictionariesLoader::qualifyDictionaryNameWithDatabase(const std::string & dictionary_name, ContextPtr query_context) const
{
if (has(dictionary_name))
return StorageID("", dictionary_name);
auto qualified_name = QualifiedTableName::tryParseFromString(dictionary_name);
if (!qualified_name)
return StorageID("", dictionary_name);
{
QualifiedTableName qualified_dictionary_name;
qualified_dictionary_name.table = dictionary_name;
return qualified_dictionary_name;
}
if (qualified_name->database.empty() && has(dictionary_name))
{
/// This is xml dictionary
return *qualified_name;
}
if (qualified_name->database.empty())
return StorageID(context->getCurrentDatabase(), dictionary_name);
qualified_name->database = query_context->getCurrentDatabase();
return StorageID("", dictionary_name);
return *qualified_name;
}
std::string ExternalDictionariesLoader::resolveDictionaryName(const std::string & dictionary_name, const std::string & current_database_name) const

View File

@ -27,7 +27,7 @@ public:
void reloadDictionary(const std::string & dictionary_name, ContextPtr context) const;
StorageID getStorageID(const std::string & dictionary_name, ContextPtr context) const;
QualifiedTableName qualifyDictionaryNameWithDatabase(const std::string & dictionary_name, ContextPtr context) const;
DictionaryStructure getDictionaryStructure(const std::string & dictionary_name, ContextPtr context) const;

View File

@ -924,7 +924,6 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
visitor.visit(*create.select);
}
if (create.columns_list)
{
AddDefaultDatabaseVisitor visitor(getContext(), current_database);

View File

@ -0,0 +1 @@
CREATE TABLE `02097_db`.test_table_default (`data_1` UInt64 DEFAULT dictGetUInt64(\'02097_db.test_dictionary\', \'data_column_1\', toUInt64(0)), `data_2` UInt8 DEFAULT dictGet(`02097_db`.test_dictionary, \'data_column_2\', toUInt64(0))) ENGINE = TinyLog

View File

@ -0,0 +1,43 @@
-- Tags: no-parallel
DROP DATABASE IF EXISTS 02097_db;
CREATE DATABASE 02097_db;
USE 02097_db;
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table
(
key_column UInt64,
data_column_1 UInt64,
data_column_2 UInt8
)
ENGINE = MergeTree
ORDER BY key_column;
DROP DICTIONARY IF EXISTS test_dictionary;
CREATE DICTIONARY test_dictionary
(
key_column UInt64 DEFAULT 0,
data_column_1 UInt64 DEFAULT 1,
data_column_2 UInt8 DEFAULT 1
)
PRIMARY KEY key_column
LAYOUT(DIRECT())
SOURCE(CLICKHOUSE(TABLE 'test_table'));
DROP TABLE IF EXISTS test_table_default;
CREATE TABLE test_table_default
(
data_1 DEFAULT dictGetUInt64('test_dictionary', 'data_column_1', toUInt64(0)),
data_2 DEFAULT dictGet(test_dictionary, 'data_column_2', toUInt64(0))
)
ENGINE=TinyLog;
SELECT create_table_query FROM system.tables WHERE name = 'test_table_default' AND database = '02097_db';
DROP DICTIONARY test_dictionary;
DROP TABLE test_table;
DROP TABLE test_table_default;
DROP DATABASE 02097_db;