diff --git a/src/Databases/DatabaseLazy.cpp b/src/Databases/DatabaseLazy.cpp index 384c5ff47dd..e6f69f797cf 100644 --- a/src/Databases/DatabaseLazy.cpp +++ b/src/Databases/DatabaseLazy.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -40,7 +41,7 @@ void DatabaseLazy::loadStoredObjects( { iterateMetadataFiles(local_context, [this](const String & file_name) { - const std::string table_name = file_name.substr(0, file_name.size() - 4); + const std::string table_name = unescapeForFileName(file_name.substr(0, file_name.size() - 4)); fs::path detached_permanently_flag = fs::path(getMetadataPath()) / (file_name + detached_suffix); if (fs::exists(detached_permanently_flag)) diff --git a/src/Databases/DatabaseOrdinary.cpp b/src/Databases/DatabaseOrdinary.cpp index 1bdb273c9fb..a122c5fc175 100644 --- a/src/Databases/DatabaseOrdinary.cpp +++ b/src/Databases/DatabaseOrdinary.cpp @@ -176,7 +176,7 @@ void DatabaseOrdinary::loadTablesMetadata(ContextPtr local_context, ParsedTables /// if (create_query->uuid != UUIDHelpers::Nil) /// DatabaseCatalog::instance().addUUIDMapping(create_query->uuid); - const std::string table_name = file_name.substr(0, file_name.size() - 4); + const std::string table_name = unescapeForFileName(file_name.substr(0, file_name.size() - 4)); LOG_DEBUG(log, "Skipping permanently detached table {}.", backQuote(table_name)); return; } diff --git a/tests/queries/0_stateless/01015_database_bad_tables.reference b/tests/queries/0_stateless/01015_database_bad_tables.reference index b69cd02f83d..917f987fda7 100644 --- a/tests/queries/0_stateless/01015_database_bad_tables.reference +++ b/tests/queries/0_stateless/01015_database_bad_tables.reference @@ -1,3 +1,5 @@ 1 1 1 1 1 1 +1 1 +1 1 diff --git a/tests/queries/0_stateless/01015_database_bad_tables.sh b/tests/queries/0_stateless/01015_database_bad_tables.sh new file mode 100755 index 00000000000..d1b63cef476 --- /dev/null +++ b/tests/queries/0_stateless/01015_database_bad_tables.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +set -e + +db="db_$CLICKHOUSE_DATABASE" +$CLICKHOUSE_CLIENT -q "DROP DATABASE IF EXISTS $db;" +$CLICKHOUSE_CLIENT -q "CREATE DATABASE $db;" +$CLICKHOUSE_CLIENT -q "CREATE TABLE $db.\`таблица_со_странным_названием\` (a UInt64, b UInt64) ENGINE = Log;" +$CLICKHOUSE_CLIENT -q "INSERT INTO $db.\`таблица_со_странным_названием\` VALUES (1, 1);" +$CLICKHOUSE_CLIENT -q "SELECT * FROM $db.\`таблица_со_странным_названием\`;" +$CLICKHOUSE_CLIENT -q "DETACH DATABASE $db;" +$CLICKHOUSE_CLIENT -q "ATTACH DATABASE $db;" +$CLICKHOUSE_CLIENT -q "SELECT * FROM $db.\`таблица_со_странным_названием\`;" +$CLICKHOUSE_CLIENT -q "DROP TABLE $db.\`таблица_со_странным_названием\`;" +$CLICKHOUSE_CLIENT -q "DROP DATABASE $db;" + +lazy_db="lazy_$CLICKHOUSE_DATABASE" +$CLICKHOUSE_CLIENT -q "DROP DATABASE IF EXISTS $lazy_db;" +$CLICKHOUSE_CLIENT -q "CREATE DATABASE $lazy_db ENGINE = Lazy(1);" +$CLICKHOUSE_CLIENT -q "CREATE TABLE $lazy_db.\`таблица_со_странным_названием\` (a UInt64, b UInt64) ENGINE = Log;" +$CLICKHOUSE_CLIENT -q "INSERT INTO $lazy_db.\`таблица_со_странным_названием\` VALUES (1, 1);" +$CLICKHOUSE_CLIENT -q "SELECT * FROM $lazy_db.\`таблица_со_странным_названием\`;" +$CLICKHOUSE_CLIENT -q "DETACH DATABASE $lazy_db;" +$CLICKHOUSE_CLIENT -q "ATTACH DATABASE $lazy_db;" +$CLICKHOUSE_CLIENT -q "SELECT * FROM $lazy_db.\`таблица_со_странным_названием\`;" +$CLICKHOUSE_CLIENT -q "DROP TABLE $lazy_db.\`таблица_со_странным_названием\`;" +$CLICKHOUSE_CLIENT -q "DROP DATABASE $lazy_db;" + +$CLICKHOUSE_CLIENT -q "CREATE DATABASE $lazy_db ENGINE = Lazy(10);" +$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS $lazy_db.test;" +$CLICKHOUSE_CLIENT -q "CREATE TABLE IF NOT EXISTS $lazy_db.test (a UInt64, b UInt64) ENGINE = Log;" +$CLICKHOUSE_CLIENT -q "CREATE TABLE IF NOT EXISTS $lazy_db.test (a UInt64, b UInt64) ENGINE = Log;" +$CLICKHOUSE_CLIENT -q "INSERT INTO $lazy_db.test VALUES (1, 1);" +$CLICKHOUSE_CLIENT -q "SELECT * FROM $lazy_db.test;" +$CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS $lazy_db.test;" +$CLICKHOUSE_CLIENT -q "DROP DATABASE $lazy_db;" diff --git a/tests/queries/0_stateless/01015_database_bad_tables.sql b/tests/queries/0_stateless/01015_database_bad_tables.sql deleted file mode 100644 index 5931b3b6fa5..00000000000 --- a/tests/queries/0_stateless/01015_database_bad_tables.sql +++ /dev/null @@ -1,24 +0,0 @@ --- Tags: no-parallel - -DROP DATABASE IF EXISTS testlazy; - -CREATE TABLE `таблица_со_странным_названием` (a UInt64, b UInt64) ENGINE = Log; -INSERT INTO `таблица_со_странным_названием` VALUES (1, 1); -SELECT * FROM `таблица_со_странным_названием`; -DROP TABLE `таблица_со_странным_названием`; - -CREATE DATABASE testlazy ENGINE = Lazy(1); -CREATE TABLE testlazy.`таблица_со_странным_названием` (a UInt64, b UInt64) ENGINE = Log; -INSERT INTO testlazy.`таблица_со_странным_названием` VALUES (1, 1); -SELECT * FROM testlazy.`таблица_со_странным_названием`; -DROP TABLE testlazy.`таблица_со_странным_названием`; -DROP DATABASE testlazy; - -CREATE DATABASE testlazy ENGINE = Lazy(10); -DROP TABLE IF EXISTS testlazy.test; -CREATE TABLE IF NOT EXISTS testlazy.test (a UInt64, b UInt64) ENGINE = Log; -CREATE TABLE IF NOT EXISTS testlazy.test (a UInt64, b UInt64) ENGINE = Log; -INSERT INTO testlazy.test VALUES (1, 1); -SELECT * FROM testlazy.test; -DROP TABLE IF EXISTS testlazy.test; -DROP DATABASE testlazy;